Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Flask==1.0.2
Keras==2.2.4
tensorflow==1.11.0
numpy
PIL
io
8 changes: 6 additions & 2 deletions run_keras_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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"] = []

Expand All @@ -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()
app.run()