Upload 8 files
Browse files- Plant_Disease_Prediction_CNN_Image_Classifier.ipynb +0 -0
- class_indices.json +1 -0
- config.toml +58 -0
- credentials.toml +3 -0
- main.py +60 -0
- plant_disease_prediction_model.h5 +3 -0
- requirements.txt +3 -0
- trained_model_link.txt +1 -0
Plant_Disease_Prediction_CNN_Image_Classifier.ipynb
ADDED
The diff for this file is too large to render.
See raw diff
|
|
class_indices.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"0": "Apple___Apple_scab", "1": "Apple___Black_rot", "2": "Apple___Cedar_apple_rust", "3": "Apple___healthy", "4": "Blueberry___healthy", "5": "Cherry_(including_sour)___Powdery_mildew", "6": "Cherry_(including_sour)___healthy", "7": "Corn_(maize)___Cercospora_leaf_spot Gray_leaf_spot", "8": "Corn_(maize)___Common_rust_", "9": "Corn_(maize)___Northern_Leaf_Blight", "10": "Corn_(maize)___healthy", "11": "Grape___Black_rot", "12": "Grape___Esca_(Black_Measles)", "13": "Grape___Leaf_blight_(Isariopsis_Leaf_Spot)", "14": "Grape___healthy", "15": "Orange___Haunglongbing_(Citrus_greening)", "16": "Peach___Bacterial_spot", "17": "Peach___healthy", "18": "Pepper,_bell___Bacterial_spot", "19": "Pepper,_bell___healthy", "20": "Potato___Early_blight", "21": "Potato___Late_blight", "22": "Potato___healthy", "23": "Raspberry___healthy", "24": "Soybean___healthy", "25": "Squash___Powdery_mildew", "26": "Strawberry___Leaf_scorch", "27": "Strawberry___healthy", "28": "Tomato___Bacterial_spot", "29": "Tomato___Early_blight", "30": "Tomato___Late_blight", "31": "Tomato___Leaf_Mold", "32": "Tomato___Septoria_leaf_spot", "33": "Tomato___Spider_mites Two-spotted_spider_mite", "34": "Tomato___Target_Spot", "35": "Tomato___Tomato_Yellow_Leaf_Curl_Virus", "36": "Tomato___Tomato_mosaic_virus", "37": "Tomato___healthy"}
|
config.toml
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[global]
|
2 |
+
# If True, will show a warning when you run a Streamlit-enabled script via "python my_script.py".
|
3 |
+
# Default: true
|
4 |
+
showWarningOnDirectExecution = true
|
5 |
+
|
6 |
+
[logger]
|
7 |
+
# Level of logging: 'error', 'warning', 'info', or 'debug'.
|
8 |
+
# Default: 'info'
|
9 |
+
level = "debug"
|
10 |
+
|
11 |
+
|
12 |
+
|
13 |
+
[runner]
|
14 |
+
# Allows you to type a variable or string by itself in a single line of Python code to write it to the app.
|
15 |
+
# Default: true
|
16 |
+
magicEnabled = true
|
17 |
+
|
18 |
+
|
19 |
+
|
20 |
+
[server]
|
21 |
+
# List of folders that should not be watched for changes. Relative paths will be taken as relative to the current working directory.
|
22 |
+
# Example: ['/home/user1/env', 'relative/path/to/folder']
|
23 |
+
# Default: []
|
24 |
+
folderWatchBlacklist = ['']
|
25 |
+
|
26 |
+
# If false, will attempt to open a browser window on start.
|
27 |
+
# Default: false unless (1) we are on a Linux box where DISPLAY is unset, or (2) server.liveSave is set.
|
28 |
+
headless = true
|
29 |
+
|
30 |
+
# Immediately share the app in such a way that enables live monitoring, and post-run analysis.
|
31 |
+
# Default: false
|
32 |
+
liveSave = false
|
33 |
+
|
34 |
+
# Automatically rerun script when the file is modified on disk.
|
35 |
+
# Default: false
|
36 |
+
runOnSave = false
|
37 |
+
|
38 |
+
# The port where the server will listen for client and browser connections.
|
39 |
+
# Default: 8501
|
40 |
+
port = 80
|
41 |
+
|
42 |
+
# Enables support for Cross-Origin Request Sharing, for added security.
|
43 |
+
# Default: true
|
44 |
+
enableCORS = false
|
45 |
+
|
46 |
+
[browser]
|
47 |
+
# Internet address of the server server that the browser should connect to. Can be IP address or DNS name.
|
48 |
+
# Default: 'localhost'
|
49 |
+
serverAddress = "0.0.0.0"
|
50 |
+
|
51 |
+
# Whether to send usage statistics to Streamlit.
|
52 |
+
# Default: true
|
53 |
+
gatherUsageStats = true
|
54 |
+
|
55 |
+
# Port that the browser should use to connect to the server when in liveSave mode.
|
56 |
+
# Default: whatever value is set in server.port.
|
57 |
+
serverPort = 80
|
58 |
+
|
credentials.toml
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
[general]
|
2 |
+
email=""
|
3 |
+
|
main.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import json
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
import numpy as np
|
6 |
+
import tensorflow as tf
|
7 |
+
import streamlit as st
|
8 |
+
|
9 |
+
|
10 |
+
working_dir = os.path.dirname(os.path.abspath(__file__))
|
11 |
+
model_path = f"{working_dir}/trained_model/plant_disease_prediction_model.h5"
|
12 |
+
# Load the pre-trained model
|
13 |
+
model = tf.keras.models.load_model(model_path)
|
14 |
+
|
15 |
+
# loading the class names
|
16 |
+
class_indices = json.load(open(f"{working_dir}/class_indices.json"))
|
17 |
+
|
18 |
+
|
19 |
+
# Function to Load and Preprocess the Image using Pillow
|
20 |
+
def load_and_preprocess_image(image_path, target_size=(224, 224)):
|
21 |
+
# Load the image
|
22 |
+
img = Image.open(image_path)
|
23 |
+
# Resize the image
|
24 |
+
img = img.resize(target_size)
|
25 |
+
# Convert the image to a numpy array
|
26 |
+
img_array = np.array(img)
|
27 |
+
# Add batch dimension
|
28 |
+
img_array = np.expand_dims(img_array, axis=0)
|
29 |
+
# Scale the image values to [0, 1]
|
30 |
+
img_array = img_array.astype('float32') / 255.
|
31 |
+
return img_array
|
32 |
+
|
33 |
+
|
34 |
+
# Function to Predict the Class of an Image
|
35 |
+
def predict_image_class(model, image_path, class_indices):
|
36 |
+
preprocessed_img = load_and_preprocess_image(image_path)
|
37 |
+
predictions = model.predict(preprocessed_img)
|
38 |
+
predicted_class_index = np.argmax(predictions, axis=1)[0]
|
39 |
+
predicted_class_name = class_indices[str(predicted_class_index)]
|
40 |
+
return predicted_class_name
|
41 |
+
|
42 |
+
|
43 |
+
# Streamlit App
|
44 |
+
st.title('Plant Disease Classifier')
|
45 |
+
|
46 |
+
uploaded_image = st.file_uploader("Upload an image...", type=["jpg", "jpeg", "png"])
|
47 |
+
|
48 |
+
if uploaded_image is not None:
|
49 |
+
image = Image.open(uploaded_image)
|
50 |
+
col1, col2 = st.columns(2)
|
51 |
+
|
52 |
+
with col1:
|
53 |
+
resized_img = image.resize((150, 150))
|
54 |
+
st.image(resized_img)
|
55 |
+
|
56 |
+
with col2:
|
57 |
+
if st.button('Classify'):
|
58 |
+
# Preprocess the uploaded image and predict the class
|
59 |
+
prediction = predict_image_class(model, uploaded_image, class_indices)
|
60 |
+
st.success(f'Prediction: {str(prediction)}')
|
plant_disease_prediction_model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b0d196c3af57c9db66072e031922fedef1a0980f2ff5d859ec203f72a31f0646
|
3 |
+
size 573706416
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
numpy==1.26.3
|
2 |
+
streamlit==1.30.0
|
3 |
+
tensorflow==2.15.0.post1
|
trained_model_link.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
trained plant disease prediction model link: https://drive.google.com/file/d/1rKh-IElSdHTqax7XdfSdZTn-r8T_qWPf/view?usp=drive_link
|