Spaces:
Runtime error
Runtime error
File size: 1,950 Bytes
8c6e404 5bc3a1e 8c6e404 bf389a9 8c6e404 b9a9c82 8b20435 8c6e404 bf389a9 8c6e404 99b8bfd 8c6e404 99b8bfd 8c6e404 99b8bfd 427829b 1f32a6c 427829b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | import streamlit as st
import tensorflow as tf
import cv2
from PIL import Image, ImageOps
import numpy as np
# Suppress warnings
import warnings
warnings.filterwarnings('ignore', category=UserWarning)
warnings.filterwarnings('ignore', category=FutureWarning)
def load_model():
model = tf.keras.models.load_model('pages/image_classification.hdf5')
return model
with st.spinner('Model is being loaded..'):
model = load_model()
st.write("# ResNet50 Model")
st.sidebar.info("You should be happy if it classifies as - Healthy plant 🙂")
file = st.file_uploader("Upload the image to be classified", type=["jpg", "png"])
st.set_option('deprecation.showfileUploaderEncoding', False)
def upload_predict(upload_image, model):
size = (180, 180)
image = ImageOps.fit(upload_image, size, Image.LANCZOS)
image = np.asarray(image)
img = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
img_resize = cv2.resize(img, dsize=(224, 224), interpolation=cv2.INTER_CUBIC)
img_reshape = img_resize[np.newaxis, ...]
prediction = model.predict(img_reshape)
print(prediction)
return prediction
if file is None:
st.text("Please upload an image file")
else:
image = Image.open(file)
st.image(image, use_column_width=True)
prediction = upload_predict(image, model)
predicted_result = np.argmax(prediction)
classfiers = ['bacterial_leaf_blight','bacterial_leaf_streak','bakanae','brown_spot','grassy_stunt_virus','healthy_rice_plant',
'narrow_brown_spot','ragged_stunt_virus','rice_blast','rice_false_smut','sheath_blight','sheath_rot','stem_rot','tungro_virus']
image_class = classfiers[predicted_result]
confidence_score = prediction[0][predicted_result]
# Results
result = f"Your plant is suffering from: *{image_class}*"
result_score = "✅ Accurate prediction score is: {} / 100".format("%.2f" % confidence_score)
st.success(result)
st.info(result_score) |