Hello community team.
I have a problem with file uploader.
I use file upload to upload images, show that image on the app.
then I use that image as input to my Keras model to make a prediction.
the code was working fine, but now it stopped and get an error message as below
" TypeError: expected str, bytes, or os.PathLike object, not _io.BytesIO "
my code in details is tw oclasses as below :
from keras.preprocessing.image import load_img from keras.preprocessing.image import img_to_array from keras.applications.vgg16 import preprocess_input from keras.applications.vgg16 import decode_predictions from keras.applications.vgg16 import VGG16 def predict(image1): model = VGG16() image = load_img(image1, target_size=(224, 224)) # convert the image pixels to a numpy array image = img_to_array(image) # reshape data for the model image = image.reshape((1, image.shape, image.shape, image.shape)) # prepare the image for the VGG model image = preprocess_input(image) # predict the probability across all output classes yhat = model.predict(image) # convert the probabilities to class labels label = decode_predictions(yhat) # retrieve the most likely result, e.g. highest probability label = label return label
import streamlit as st from PIL import Image from classify import predict st.title("Upload + Classification Example") uploaded_file = st.file_uploader("Choose an image...", type="jpg") if uploaded_file is not None: image = Image.open(uploaded_file) st.image(image, caption='Uploaded Image.', use_column_width=True) st.write("") st.write("Classifying...") label = predict(uploaded_file) st.write('%s (%.2f%%)' % (label, label*100))
the error in details :
TypeError: expected str, bytes or os.PathLike object, not _io.BytesIO Traceback:
File "d:\users\bassam\anaconda3\lib\site-packages\streamlit\ScriptRunner.py", line 319, in _run_script exec(code, module.__dict__) File "C:\Users\Bassam\upload.py", line 38, in <module> label = predict(uploaded_file) File "C:\Users\Bassam\classify1.py", line 9, in predict image = load_img(image1, target_size=(224, 224)) File "d:\users\bassam\anaconda3\lib\site-packages\keras_preprocessing\image\utils.py", line 113, in load_img with open(path, 'rb') as f: