Spaces:
Runtime error
Runtime error
ml models
Browse filesFiles changed (6)
- .gitattributes+1
- app/pages/.gitattributesAdded+1
- app/pages/ResNet50_Model.pyAdded+57
- app/pages/Teachable_Machine_Model.pyAdded+79
- app/pages/image_classification.hdf5Added+3
- app/pages/labels.txtAdded+14
33 unmodified lines34353633 unmodified lines*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -textapp/artifactory/image_classification.hdf5 filter=lfs diff=lfs merge=lfs -text33 unmodified lines3435363733 unmodified lines*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -textapp/artifactory/image_classification.hdf5 filter=lfs diff=lfs merge=lfs -textapp/pages/image_classification.hdf5 filter=lfs diff=lfs merge=lfs -text
1*.hdf5 filter=lfs diff=lfs merge=lfs -text123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657import streamlit as stimport tensorflow as tfimport cv2from PIL import Image, ImageOpsimport numpy as np
# Suppress warningsimport warningswarnings.filterwarnings('ignore', category=UserWarning)warnings.filterwarnings('ignore', category=FutureWarning)
def load_model(): model = tf.keras.models.load_model('app/artifactory/image_classification.hdf5') return model
with st.spinner('Model is being loaded..'): model = load_model()
st.write(""" # Rice Disease Classifier """ )
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.ANTIALIAS) 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) print(predicted_result) 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] st.write("The image is classified as", image_class) st.write("The similarity score is approximately", confidence_score, "/1") print("The image is classified as ", image_class, "with a similarity score of", confidence_score)12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879#!pip install keras tensorflow scikit-learn pillow seaborn# Trained on 80 epochs at Batch size 256 with Learning Rate of 0.001 under 50 seconds!!
from PIL import Image, ImageOps # Install pillow instead of PILimport numpy as np
import streamlit as stimport tensorflow as tf
# Suppress warningsimport warningswarnings.filterwarnings('ignore', category=UserWarning)warnings.filterwarnings('ignore', category=FutureWarning)# Disable scientific notation for claritynp.set_printoptions(suppress=True)
def load_model_teachable(): # Load the model model = tf.keras.models.load_model("app/artifactory/keras_model.h5") return model
with st.spinner('Model is being loaded..'): model = load_model_teachable()
st.write(""" # Teachable Machine Model """ )
file = st.file_uploader("Upload the image to be classified", type=["jpg", "png"])st.set_option('deprecation.showfileUploaderEncoding', False)
def upload_predict_teachable(image, model, class_names):
# Create the array of the right shape to feed into the keras model # The 'length' or number of images you can put into the array is # determined by the first position in the shape tuple, in this case 1 data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
# Replace this with the path to your image image_RGB = image.convert("RGB")
# resizing the image to be at least 224x224 and then cropping from the center # size = (224, 224) # image = ImageOps.fit(image, size, Image.Resampling.LANCZOS)
image_resized = image_RGB.resize((224, 224), resample=Image.LANCZOS)
# turn the image into a numpy array image_array = np.asarray(image_resized)
# Normalize the image normalized_image_array = (image_array.astype(np.float32) / 127.5) - 1
# Load the image into the array data[0] = normalized_image_array
# Predicts the model prediction = model.predict(data) 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) # Load the labels class_names = open("app/artifactory/labels.txt", "r").readlines() prediction = upload_predict_teachable(image, model,class_names) index = np.argmax(prediction) class_name = class_names[index] confidence_score = prediction[0][index]
# Print prediction and confidence score st.write("The image is classified as", class_name) st.write("The similarity score is approximately", confidence_score, "/1") print("The image is classified as ", class_name, "with a similarity score of", confidence_score)123version https://git-lfs.github.com/spec/v1oid sha256:9ac65a4e8de833072036a113d1923c12c4ed4d58a309afa2a1202a43360b76fdsize 28987942412345678910111213140 Blast1 False smut2 Brown spot3 Narrow spot4 Sheath bligh...5 Sheath rot6 Stem rot7 Bakanae8 BLB9 BLS10 Grassy stunt...11 Ragged virus12 Tungro virus13 Healthy.gitattributes+1
app/pages/.gitattributesAdded+1
app/pages/ResNet50_Model.pyAdded+57
app/pages/Teachable_Machine_Model.pyAdded+79
app/pages/image_classification.hdf5Added+3
app/pages/labels.txtAdded+14