question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

expected str, bytes or os.PathLike object, not Sequential

See original GitHub issue

I am trying to deploy my Image Classification model and facing this issue while reading the selected image.

Code snippet:

def prediction(model):
    image_file = st.file_uploader("Choose a bird image..", type="jpg")
    if(image_file is not None): 
        image = Image.open(image_file)
        st.image(image, width=40, caption='Uploaded bird image', use_column_width=True)
        np_image = np.array(image).astype('float32')/255
        np_image = transform.resize(np_image, (224, 224, 3))
        np_image = np.expand_dims(np_image, axis=0)
        model = load_model(model)
        prediction = model.predict(img.reshape(1,224,224,3))
                
        if(np.argmax(prediction)==0.0):
            st.write('According to Model, it can be: COVID-19 with an Accuracy of {0:.2f}%'.format(np.max(prediction)*100))
        elif(np.argmax(prediction)==1.0):
            st.write('According to Model, it can be: Normal with an Accuracy of {0:.2f}%'.format(np.max(prediction)*100))
        elif(np.argmax(prediction)==2.0):
            st.write('According to Model, it can be: Pneumonia with an Accuracy of {0:.2f}%'.format(np.max(prediction)*100))

I executed the same code a month ago, and it worked fine—Donno why I am facing this error now.

Debug info

  • Streamlit version: 0.72.0
  • Python version: Python 3.7.5
  • Tensorflow Version: tensorflow==2.4.1
  • Keras Version: Keras==2.3.1
  • Using IDLE
  • OS version: Windows
  • Browser version: Chrome

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
snehitvaddicommented, Mar 18, 2021

Yes @kmcgrady , I did use file.read()
code: image = Image.open(io.BytesIO(file.read())) .

I came across some working code as given below:

def prediction(model):
    file = st.file_uploader("Choose a X-Ray image..", type=["jpg","png"])
    if(file is not None):
        img = Image.open(file)
        img = ImageOps.fit(img,(224,224))
        img = np.asarray(img)
        img_reshape = img[np.newaxis,...]
        
        st.image(img, width=40, caption='Uploaded X-ray image', use_column_width=True)
        st.write("")
        st.write("Classifying...")
        prediction = model.predict(img_reshape)

        print(np.argmax(prediction))
        if(np.argmax(prediction)==0.0):
            st.write('According to Model, it can be: COVID-19 with an Accuracy of {0:.2f}%'.format(np.max(prediction)*100))
        elif(np.argmax(prediction)==1.0):
            st.write('According to Model, it can be: Normal with an Accuracy of {0:.2f}%'.format(np.max(prediction)*100))
        elif(np.argmax(prediction)==2.0):
            st.write('According to Model, it can be: Pneumonia with an Accuracy of {0:.2f}%'.format(np.max(prediction)*100))

Right now, I’m facing two issues.

Issue-1: Here, the Model is wrongly predicting images on Streamlit. I tested the model on Jupyter notebook, and it predicted correctly there.

Issue-2: This worked fine without any errors for images in the same directory but raising errors for images on other directories as below images.

0reactions
kmcgradycommented, May 23, 2021

I am going to close this issue after not hearing anything back. Feel free to reopen it if you are still seeing issues.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: expected str, bytes or os.PathLike object, not _io ...
I think it has to do with your second element in storbinary . You are trying to open file , but it is...
Read more >
Expected str, bytes or os.PathLike object, not TextIOWrapper
The Python "TypeError: expected str, bytes or os.PathLike object, not TextIOWrapper" occurs when we pass a file object instead of a string when ......
Read more >
Backups to remote storage fail with "expected str, bytes or os ...
Username: TITLE Backups to remote storage fail with "expected str, bytes or os.PathLike object, not int" PRODUCT, VERSION, OPERATING SYSTEM.
Read more >
expected str, bytes or os.PathLike object, not function - Reddit
I have this task: load_io_monthly_billing_to_snowflake = SnowflakeLoadOperator( task_id='load_io_monthly_billing_to_Snowflake'…
Read more >
TypeError: expected str, bytes or os.PathLike object, not int #6
When I used the command “python setup.py install” to download the mimkl package, an error occurred: "TypeError: expected str, bytes or os.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found