I have an Image object that is required to be passed to the client side and display on the page. Below is what I tried but to not avail.
The model_predict function is receiving the image from client for classification. After the classification has been done then the model will generate an image to be passed back to the client in function upload().
def model_predict(img_path, model):
img = image.load_img(img_path, target_size=(224, 224))
...
leaf_result = cv2.bitwise_and(img, img, mask=mask)
im = Image.fromarray(leaf_result)
# decoded_class = decode(img)
im.save(f"./output.png")
preds = model.predict(x)
return preds,im
@app.route('/predict', methods=['GET', 'POST'])
def upload():
if request.method == 'POST':
# Get the file from post request
f = request.files['file']
# Save the file to ./uploads
basepath = os.path.dirname(__file__)
file_path = os.path.join(
basepath, 'uploads', secure_filename(f.filename))
f.save(file_path)
prediction, im = model_predict(file_path, model)
....
result_list = list()
result_list.append(prediction1)
result_list.append(prediction2)
return jsonify(result_list, base64.decodebytes(im))
return None