keras-and-tensorflow-serving icon indicating copy to clipboard operation
keras-and-tensorflow-serving copied to clipboard

expected str, bytes or os.PathLike object, not _io.BytesIO

Open omerasif57 opened this issue 3 years ago • 1 comments

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()

omerasif57 avatar Jul 14 '21 11:07 omerasif57

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.

omerasif57 avatar Jul 14 '21 13:07 omerasif57