keras-and-tensorflow-serving
keras-and-tensorflow-serving copied to clipboard
expected str, bytes or os.PathLike object, not _io.BytesIO
while running flask_sample_request.py
File "/home/abril/.pyenv/versions/3.6.7/envs/env36/lib/python3.6/site-packages/keras_preprocessing/image/utils.py", line 113, in load_img
with open(path, 'rb') as f:
TypeError: expected str, bytes or os.PathLike object, not _io.BytesIO
Guess, we need to convert/save bytes to a file and then read in image.load_img()
Solved using:
bytes = BytesIO(base64.b64decode(request.form['b64']))
inimg = Image.open(bytes)
inimg = inimg.convert('RGB')
inimg.save("input_image.jpg")
img = image.img_to_array(image.load_img("input_image.jpg", target_size=(224, 224))) / 255.
use inimg = inimg.convert('RGB')
for jpg file else throw error.