I’m trying to upload an image for my binary classification model,
but constantly getting this error.
I’ve used the other solutions mentioned in the forum, but still its not resolved.
Please help.
Here’s the code snippet:-
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing.image import img_to_array, load_img
import numpy as np
import streamlit as st
from PIL import Image
st.title("Covid19 Detection")
def prediction(model):
image_file = st.file_uploader("Choose an image...", type="jpg")
if (image_file is not None):
img = load_img(image_file, target_size=(256,256), color_mode = "grayscale")
img = img_to_array(img)
img = Image.open(img)
st.image(img,width=40, caption='Uploaded Image', use_column_width=True)
st.write("")
st.write("Detecting......")
img = img/255
classes = model.predict(img.reshape(1,256,256,1))
if classes[0][0] == 1:
prediction = 'Not Detected'
else:
prediction = 'Covid Detected!'
print(prediction)
return
def loading_model():
model = load_model('Covid_model.hdf5')
print('Model Loaded')
return model
model = loading_model()
prediction(model)
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.