@@ -265,13 +265,13 @@ def create_training_data_keras(source_path, save_path = None, image_size = (224,
265265 return x , y
266266
267267
268- def make_prediction_from_directory_keras (images_path , keras_model_path , image_size = (224 ,224 ), print_output = True , model_summary = True , show_images = False , grayscale = False , files_to_exclude = [".DS_Store" ,"" ]):
268+ def make_prediction_from_directory_keras (images_path , keras_model , image_size = (224 ,224 ), print_output = True , model_summary = True , show_images = False , grayscale = False , files_to_exclude = [".DS_Store" ,"" ]):
269269 """
270270 Reads test data from directory resizes it and makes prediction with using a keras model
271271
272272 # Arguments:
273273 images_path: source path of the test images see input format
274- keras_model_path: path of the keras model
274+ keras_model: a keras model object or path of the model
275275 img_size (224): size of the images for resizing
276276 print_output (True): prints output
277277 model_summary (True): shows keras model summary
@@ -323,8 +323,11 @@ def make_prediction_from_directory_keras(images_path, keras_model_path, image_si
323323 if exclude in images :
324324 images .remove (exclude )
325325
326- # load model
327- model = keras .models .load_model (keras_model_path )
326+ # prepare model
327+ if (isinstance (keras_model , keras .Model )):
328+ model = keras_model
329+ else :
330+ model = keras .models .load_model (keras_model )
328331
329332 # get all images
330333 for image in images :
@@ -367,13 +370,13 @@ def make_prediction_from_directory_keras(images_path, keras_model_path, image_si
367370 return predictions
368371
369372
370- def make_prediction_from_array_keras (test_x , keras_model_path , print_output = True , model_summary = True , show_images = False ):
373+ def make_prediction_from_array_keras (test_x , keras_model , print_output = True , model_summary = True , show_images = False ):
371374 """
372375 makes prediction with using a keras model
373376
374377 # Arguments:
375378 test_x: numpy array of images
376- keras_model_path: path of the keras model
379+ keras_model: a keras model object or path of the model
377380 print_output (True): prints output
378381 model_summary (True): shows keras model summary
379382 show_images (False): shows the predicted image
@@ -392,8 +395,11 @@ def make_prediction_from_array_keras(test_x, keras_model_path, print_output=True
392395 import keras
393396 import cv2
394397
395- # load model
396- model = keras .models .load_model (keras_model_path )
398+ # prepare model
399+ if (isinstance (keras_model , keras .Model )):
400+ model = keras_model
401+ else :
402+ model = keras .models .load_model (keras_model )
397403
398404 # show model summary
399405 if (model_summary ):
0 commit comments