Spaces:
Runtime error
Runtime error
ml models
Browse files- .gitattributes +1 -0
- app/pages/.gitattributes +1 -0
- app/pages/ResNet50_Model.py +57 -0
- app/pages/Teachable_Machine_Model.py +79 -0
- app/pages/image_classification.hdf5 +3 -0
- app/pages/labels.txt +14 -0
.gitattributes
CHANGED
|
@@ -34,3 +34,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
app/artifactory/image_classification.hdf5 filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
app/artifactory/image_classification.hdf5 filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
app/pages/image_classification.hdf5 filter=lfs diff=lfs merge=lfs -text
|
app/pages/.gitattributes
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
*.hdf5 filter=lfs diff=lfs merge=lfs -text
|
app/pages/ResNet50_Model.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import cv2
|
| 4 |
+
from PIL import Image, ImageOps
|
| 5 |
+
import numpy as np
|
| 6 |
+
|
| 7 |
+
# Suppress warnings
|
| 8 |
+
import warnings
|
| 9 |
+
warnings.filterwarnings('ignore', category=UserWarning)
|
| 10 |
+
warnings.filterwarnings('ignore', category=FutureWarning)
|
| 11 |
+
|
| 12 |
+
def load_model():
|
| 13 |
+
model = tf.keras.models.load_model('app/artifactory/image_classification.hdf5')
|
| 14 |
+
return model
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
with st.spinner('Model is being loaded..'):
|
| 18 |
+
model = load_model()
|
| 19 |
+
|
| 20 |
+
st.write("""
|
| 21 |
+
# Rice Disease Classifier
|
| 22 |
+
"""
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
file = st.file_uploader("Upload the image to be classified", type=["jpg", "png"])
|
| 26 |
+
st.set_option('deprecation.showfileUploaderEncoding', False)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def upload_predict(upload_image, model):
|
| 30 |
+
size = (180, 180)
|
| 31 |
+
image = ImageOps.fit(upload_image, size, Image.ANTIALIAS)
|
| 32 |
+
image = np.asarray(image)
|
| 33 |
+
img = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
| 34 |
+
img_resize = cv2.resize(img, dsize=(224, 224), interpolation=cv2.INTER_CUBIC)
|
| 35 |
+
|
| 36 |
+
img_reshape = img_resize[np.newaxis, ...]
|
| 37 |
+
|
| 38 |
+
prediction = model.predict(img_reshape)
|
| 39 |
+
print(prediction)
|
| 40 |
+
return prediction
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
if file is None:
|
| 44 |
+
st.text("Please upload an image file")
|
| 45 |
+
else:
|
| 46 |
+
image = Image.open(file)
|
| 47 |
+
st.image(image, use_column_width=True)
|
| 48 |
+
prediction = upload_predict(image, model)
|
| 49 |
+
predicted_result = np.argmax(prediction)
|
| 50 |
+
print(predicted_result)
|
| 51 |
+
classfiers = ['bacterial_leaf_blight','bacterial_leaf_streak','bakanae','brown_spot','grassy_stunt_virus','healthy_rice_plant',
|
| 52 |
+
'narrow_brown_spot','ragged_stunt_virus','rice_blast','rice_false_smut','sheath_blight','sheath_rot','stem_rot','tungro_virus']
|
| 53 |
+
image_class = classfiers[predicted_result]
|
| 54 |
+
confidence_score = prediction[0][predicted_result]
|
| 55 |
+
st.write("The image is classified as", image_class)
|
| 56 |
+
st.write("The similarity score is approximately", confidence_score, "/1")
|
| 57 |
+
print("The image is classified as ", image_class, "with a similarity score of", confidence_score)
|
app/pages/Teachable_Machine_Model.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!pip install keras tensorflow scikit-learn pillow seaborn
|
| 2 |
+
# Trained on 80 epochs at Batch size 256 with Learning Rate of 0.001 under 50 seconds!!
|
| 3 |
+
|
| 4 |
+
from PIL import Image, ImageOps # Install pillow instead of PIL
|
| 5 |
+
import numpy as np
|
| 6 |
+
|
| 7 |
+
import streamlit as st
|
| 8 |
+
import tensorflow as tf
|
| 9 |
+
|
| 10 |
+
# Suppress warnings
|
| 11 |
+
import warnings
|
| 12 |
+
warnings.filterwarnings('ignore', category=UserWarning)
|
| 13 |
+
warnings.filterwarnings('ignore', category=FutureWarning)
|
| 14 |
+
# Disable scientific notation for clarity
|
| 15 |
+
np.set_printoptions(suppress=True)
|
| 16 |
+
|
| 17 |
+
def load_model_teachable():
|
| 18 |
+
# Load the model
|
| 19 |
+
model = tf.keras.models.load_model("app/artifactory/keras_model.h5")
|
| 20 |
+
return model
|
| 21 |
+
|
| 22 |
+
with st.spinner('Model is being loaded..'):
|
| 23 |
+
model = load_model_teachable()
|
| 24 |
+
|
| 25 |
+
st.write("""
|
| 26 |
+
# Teachable Machine Model
|
| 27 |
+
"""
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
file = st.file_uploader("Upload the image to be classified", type=["jpg", "png"])
|
| 31 |
+
st.set_option('deprecation.showfileUploaderEncoding', False)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def upload_predict_teachable(image, model, class_names):
|
| 35 |
+
|
| 36 |
+
# Create the array of the right shape to feed into the keras model
|
| 37 |
+
# The 'length' or number of images you can put into the array is
|
| 38 |
+
# determined by the first position in the shape tuple, in this case 1
|
| 39 |
+
data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
|
| 40 |
+
|
| 41 |
+
# Replace this with the path to your image
|
| 42 |
+
image_RGB = image.convert("RGB")
|
| 43 |
+
|
| 44 |
+
# resizing the image to be at least 224x224 and then cropping from the center
|
| 45 |
+
# size = (224, 224)
|
| 46 |
+
# image = ImageOps.fit(image, size, Image.Resampling.LANCZOS)
|
| 47 |
+
|
| 48 |
+
image_resized = image_RGB.resize((224, 224), resample=Image.LANCZOS)
|
| 49 |
+
|
| 50 |
+
# turn the image into a numpy array
|
| 51 |
+
image_array = np.asarray(image_resized)
|
| 52 |
+
|
| 53 |
+
# Normalize the image
|
| 54 |
+
normalized_image_array = (image_array.astype(np.float32) / 127.5) - 1
|
| 55 |
+
|
| 56 |
+
# Load the image into the array
|
| 57 |
+
data[0] = normalized_image_array
|
| 58 |
+
|
| 59 |
+
# Predicts the model
|
| 60 |
+
prediction = model.predict(data)
|
| 61 |
+
return prediction
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
if file is None:
|
| 65 |
+
st.text("Please upload an image file")
|
| 66 |
+
else:
|
| 67 |
+
image = Image.open(file)
|
| 68 |
+
st.image(image, use_column_width=True)
|
| 69 |
+
# Load the labels
|
| 70 |
+
class_names = open("app/artifactory/labels.txt", "r").readlines()
|
| 71 |
+
prediction = upload_predict_teachable(image, model,class_names)
|
| 72 |
+
index = np.argmax(prediction)
|
| 73 |
+
class_name = class_names[index]
|
| 74 |
+
confidence_score = prediction[0][index]
|
| 75 |
+
|
| 76 |
+
# Print prediction and confidence score
|
| 77 |
+
st.write("The image is classified as", class_name)
|
| 78 |
+
st.write("The similarity score is approximately", confidence_score, "/1")
|
| 79 |
+
print("The image is classified as ", class_name, "with a similarity score of", confidence_score)
|
app/pages/image_classification.hdf5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9ac65a4e8de833072036a113d1923c12c4ed4d58a309afa2a1202a43360b76fd
|
| 3 |
+
size 289879424
|
app/pages/labels.txt
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
0 Blast
|
| 2 |
+
1 False smut
|
| 3 |
+
2 Brown spot
|
| 4 |
+
3 Narrow spot
|
| 5 |
+
4 Sheath bligh...
|
| 6 |
+
5 Sheath rot
|
| 7 |
+
6 Stem rot
|
| 8 |
+
7 Bakanae
|
| 9 |
+
8 BLB
|
| 10 |
+
9 BLS
|
| 11 |
+
10 Grassy stunt...
|
| 12 |
+
11 Ragged virus
|
| 13 |
+
12 Tungro virus
|
| 14 |
+
13 Healthy
|