I am using keras' pre-trained model and the error came up when trying to get predictions. I have the following code in flask server:
from NeuralNetwork import *
@app.route("/uploadMultipleImages", methods=["POST"])
def uploadMultipleImages():
uploaded_files = request.files.getlist("file[]")
getPredictionfunction = preTrainedModel["VGG16"]
for file in uploaded_files:
path = os.path.join(STATIC_PATH, file.filename)
result = getPredictionfunction(path)
This is what I have in my NeuralNetwork.py file:
vgg16 = VGG16(weights='imagenet', include_top=True)
def getVGG16Prediction(img_path):
model = vgg16
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
pred = model.predict(x) #ERROR HERE
return sort(decode_predictions(pred, top=3)[0])
preTrainedModel["VGG16"] = getVGG16Prediction
However, running this code below, does not create any error:
if __name__ == "__main__":
STATIC_PATH = os.getcwd()+"/static"
print(preTrainedModel["VGG16"](STATIC_PATH+"/18.jpg"))
Any comment or suggestion is greatly appreciated. Thank you.