From 2b415e2426311245aa52ea2ac0c9b40b4dcb8908 Mon Sep 17 00:00:00 2001 From: robmarkcole Date: Sat, 18 May 2019 12:14:43 +0100 Subject: [PATCH] Fix predictions --- requirements.txt | 6 ++++++ run_keras_server.py | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f9338ce --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +Flask==1.0.2 +Keras==2.2.4 +tensorflow==1.11.0 +numpy +PIL +io diff --git a/run_keras_server.py b/run_keras_server.py index d20d79c..3d3f98b 100644 --- a/run_keras_server.py +++ b/run_keras_server.py @@ -7,6 +7,7 @@ # python simple_request.py # import the necessary packages +import tensorflow as tf from keras.applications import ResNet50 from keras.preprocessing.image import img_to_array from keras.applications import imagenet_utils @@ -25,6 +26,8 @@ def load_model(): # substitute in your own networks just as easily) global model model = ResNet50(weights="imagenet") + global graph + graph = tf.get_default_graph() def prepare_image(image, target): # if the image mode is not RGB, convert it @@ -58,7 +61,8 @@ def predict(): # classify the input image and then initialize the list # of predictions to return to the client - preds = model.predict(image) + with graph.as_default(): + preds = model.predict(image) results = imagenet_utils.decode_predictions(preds) data["predictions"] = [] @@ -80,4 +84,4 @@ def predict(): print(("* Loading Keras model and Flask starting server..." "please wait until server has fully started")) load_model() - app.run() \ No newline at end of file + app.run()