kero2111 commited on
Commit
b6a5f5d
·
verified ·
1 Parent(s): 56aadc5

Upload folder using huggingface_hub

Browse files
Pretrained_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6ddcc03cc1927fc884942c56dbda0902e43cdf36fa6434d6f1e31da155590c95
3
+ size 658882872
README.md ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Plant Disease Classification Model
2
+
3
+ This repository contains a pre-trained InceptionResNetV2 model for plant disease classification. The model can classify 38 different plant diseases and healthy conditions across various plant species.
4
+
5
+ ## Model Information
6
+
7
+ - **Framework**: Keras/TensorFlow
8
+ - **Architecture**: InceptionResNetV2
9
+ - **Task**: Image Classification
10
+ - **Number of Classes**: 38
11
+ - **Input Shape**: (224, 224, 3) - RGB images
12
+ - **Output**: Probability distribution over 38 classes
13
+
14
+ ## Supported Plant Species and Conditions
15
+
16
+ The model can classify the following plant species and their conditions:
17
+
18
+ ### Apple
19
+ - Apple scab
20
+ - Black rot
21
+ - Cedar apple rust
22
+ - Healthy
23
+
24
+ ### Blueberry
25
+ - Healthy
26
+
27
+ ### Cherry (including sour)
28
+ - Powdery mildew
29
+ - Healthy
30
+
31
+ ### Corn (maize)
32
+ - Cercospora leaf spot Gray leaf spot
33
+ - Common rust
34
+ - Northern Leaf Blight
35
+ - Healthy
36
+
37
+ ### Grape
38
+ - Black rot
39
+ - Esca (Black Measles)
40
+ - Leaf blight (Isariopsis Leaf Spot)
41
+ - Healthy
42
+
43
+ ### Orange
44
+ - Haunglongbing (Citrus greening)
45
+
46
+ ### Peach
47
+ - Bacterial spot
48
+ - Healthy
49
+
50
+ ### Pepper, bell
51
+ - Bacterial spot
52
+ - Healthy
53
+
54
+ ### Potato
55
+ - Early blight
56
+ - Late blight
57
+ - Healthy
58
+
59
+ ### Raspberry
60
+ - Healthy
61
+
62
+ ### Soybean
63
+ - Healthy
64
+
65
+ ### Squash
66
+ - Powdery mildew
67
+
68
+ ### Strawberry
69
+ - Leaf scorch
70
+ - Healthy
71
+
72
+ ### Tomato
73
+ - Bacterial spot
74
+ - Early blight
75
+ - Late blight
76
+ - Leaf Mold
77
+ - Septoria leaf spot
78
+ - Spider mites Two-spotted spider mite
79
+ - Target Spot
80
+ - Tomato Yellow Leaf Curl Virus
81
+ - Tomato mosaic virus
82
+ - Healthy
83
+
84
+ ## Usage
85
+
86
+ ### Loading the Model
87
+
88
+ ```python
89
+ import tensorflow as tf
90
+ from huggingface_hub import hf_hub_download
91
+
92
+ # Download the model from Hugging Face
93
+ model_path = hf_hub_download(
94
+ repo_id="kero2111/Plant_Disease",
95
+ filename="Pretrained_model.h5"
96
+ )
97
+
98
+ # Load the model
99
+ model = tf.keras.models.load_model(model_path)
100
+ ```
101
+
102
+ ### Making Predictions
103
+
104
+ ```python
105
+ import numpy as np
106
+ from PIL import Image
107
+
108
+ # Load and preprocess image
109
+ def preprocess_image(image_path):
110
+ img = Image.open(image_path)
111
+ img = img.resize((224, 224))
112
+ img = np.array(img) / 255.0
113
+ img = np.expand_dims(img, axis=0)
114
+ return img
115
+
116
+ # Make prediction
117
+ image = preprocess_image("path_to_your_image.jpg")
118
+ prediction = model.predict(image)
119
+ predicted_class = np.argmax(prediction[0])
120
+ confidence = prediction[0][predicted_class]
121
+
122
+ # Get class name
123
+ classes = [
124
+ "Apple___Apple_scab", "Apple___Black_rot", "Apple___Cedar_apple_rust", "Apple___healthy",
125
+ "Blueberry___healthy", "Cherry_(including_sour)___Powdery_mildew", "Cherry_(including_sour)___healthy",
126
+ "Corn_(maize)___Cercospora_leaf_spot Gray_leaf_spot", "Corn_(maize)___Common_rust_",
127
+ "Corn_(maize)___Northern_Leaf_Blight", "Corn_(maize)___healthy", "Grape___Black_rot",
128
+ "Grape___Esca_(Black_Measles)", "Grape___Leaf_blight_(Isariopsis_Leaf_Spot)", "Grape___healthy",
129
+ "Orange___Haunglongbing_(Citrus_greening)", "Peach___Bacterial_spot", "Peach___healthy",
130
+ "Pepper,_bell___Bacterial_spot", "Pepper,_bell___healthy", "Potato___Early_blight",
131
+ "Potato___Late_blight", "Potato___healthy", "Raspberry___healthy", "Soybean___healthy",
132
+ "Squash___Powdery_mildew", "Strawberry___Leaf_scorch", "Strawberry___healthy",
133
+ "Tomato___Bacterial_spot", "Tomato___Early_blight", "Tomato___Late_blight", "Tomato___Leaf_Mold",
134
+ "Tomato___Septoria_leaf_spot", "Tomato___Spider_mites Two-spotted_spider_mite",
135
+ "Tomato___Target_Spot", "Tomato___Tomato_Yellow_Leaf_Curl_Virus", "Tomato___Tomato_mosaic_virus",
136
+ "Tomato___healthy"
137
+ ]
138
+
139
+ print(f"Predicted: {classes[predicted_class]}")
140
+ print(f"Confidence: {confidence:.2%}")
141
+ ```
142
+
143
+ ## Model Performance
144
+
145
+ The model has been trained on a comprehensive dataset of plant disease images and can accurately classify various plant diseases and healthy conditions.
146
+
147
+ ## Requirements
148
+
149
+ - TensorFlow 2.x
150
+ - NumPy
151
+ - PIL (Pillow)
152
+ - huggingface_hub
153
+
154
+ ## License
155
+
156
+ This model is provided for research and educational purposes.
157
+
158
+ ## Citation
159
+
160
+ If you use this model in your research, please cite the original dataset and model architecture used.
Readme.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ Encoding classes name for deployment :
2
+ 'Apple___Apple_scab': 0, 'Apple___Black_rot': 1, 'Apple___Cedar_apple_rust': 2, 'Apple___healthy': 3, 'Blueberry___healthy': 4, 'Cherry_(including_sour)___Powdery_mildew': 5, 'Cherry_(including_sour)___healthy': 6, 'Corn_(maize)___Cercospora_leaf_spot Gray_leaf_spot': 7, 'Corn_(maize)___Common_rust_': 8, 'Corn_(maize)___Northern_Leaf_Blight': 9, 'Corn_(maize)___healthy': 10, 'Grape___Black_rot': 11, 'Grape___Esca_(Black_Measles)': 12, 'Grape___Leaf_blight_(Isariopsis_Leaf_Spot)': 13, 'Grape___healthy': 14, 'Orange___Haunglongbing_(Citrus_greening)': 15, 'Peach___Bacterial_spot': 16, 'Peach___healthy': 17, 'Pepper,_bell___Bacterial_spot': 18, 'Pepper,_bell___healthy': 19, 'Potato___Early_blight': 20, 'Potato___Late_blight': 21, 'Potato___healthy': 22, 'Raspberry___healthy': 23, 'Soybean___healthy': 24, 'Squash___Powdery_mildew': 25, 'Strawberry___Leaf_scorch': 26, 'Strawberry___healthy': 27, 'Tomato___Bacterial_spot': 28, 'Tomato___Early_blight': 29, 'Tomato___Late_blight': 30, 'Tomato___Leaf_Mold': 31, 'Tomato___Septoria_leaf_spot': 32, 'Tomato___Spider_mites Two-spotted_spider_mite': 33, 'Tomato___Target_Spot': 34, 'Tomato___Tomato_Yellow_Leaf_Curl_Virus': 35, 'Tomato___Tomato_mosaic_virus': 36, 'Tomato___healthy': 37
config.json ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_type": "keras",
3
+ "framework": "keras",
4
+ "task": "image-classification",
5
+ "model_name": "plant-disease-classifier",
6
+ "description": "A pre-trained InceptionResNetV2 model for plant disease classification",
7
+ "num_classes": 38,
8
+ "classes": [
9
+ "Apple___Apple_scab",
10
+ "Apple___Black_rot",
11
+ "Apple___Cedar_apple_rust",
12
+ "Apple___healthy",
13
+ "Blueberry___healthy",
14
+ "Cherry_(including_sour)___Powdery_mildew",
15
+ "Cherry_(including_sour)___healthy",
16
+ "Corn_(maize)___Cercospora_leaf_spot Gray_leaf_spot",
17
+ "Corn_(maize)___Common_rust_",
18
+ "Corn_(maize)___Northern_Leaf_Blight",
19
+ "Corn_(maize)___healthy",
20
+ "Grape___Black_rot",
21
+ "Grape___Esca_(Black_Measles)",
22
+ "Grape___Leaf_blight_(Isariopsis_Leaf_Spot)",
23
+ "Grape___healthy",
24
+ "Orange___Haunglongbing_(Citrus_greening)",
25
+ "Peach___Bacterial_spot",
26
+ "Peach___healthy",
27
+ "Pepper,_bell___Bacterial_spot",
28
+ "Pepper,_bell___healthy",
29
+ "Potato___Early_blight",
30
+ "Potato___Late_blight",
31
+ "Potato___healthy",
32
+ "Raspberry___healthy",
33
+ "Soybean___healthy",
34
+ "Squash___Powdery_mildew",
35
+ "Strawberry___Leaf_scorch",
36
+ "Strawberry___healthy",
37
+ "Tomato___Bacterial_spot",
38
+ "Tomato___Early_blight",
39
+ "Tomato___Late_blight",
40
+ "Tomato___Leaf_Mold",
41
+ "Tomato___Septoria_leaf_spot",
42
+ "Tomato___Spider_mites Two-spotted_spider_mite",
43
+ "Tomato___Target_Spot",
44
+ "Tomato___Tomato_Yellow_Leaf_Curl_Virus",
45
+ "Tomato___Tomato_mosaic_virus",
46
+ "Tomato___healthy"
47
+ ]
48
+ }
inference.py ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tensorflow as tf
2
+ import numpy as np
3
+ from PIL import Image
4
+ import os
5
+
6
+ def load_model(model_path):
7
+ """
8
+ Load the pre-trained plant disease classification model
9
+ """
10
+ try:
11
+ model = tf.keras.models.load_model(model_path)
12
+ print("Model loaded successfully!")
13
+ return model
14
+ except Exception as e:
15
+ print(f"Error loading model: {e}")
16
+ return None
17
+
18
+ def preprocess_image(image_path, target_size=(224, 224)):
19
+ """
20
+ Preprocess image for model inference
21
+ """
22
+ try:
23
+ # Load image
24
+ img = Image.open(image_path)
25
+
26
+ # Convert to RGB if necessary
27
+ if img.mode != 'RGB':
28
+ img = img.convert('RGB')
29
+
30
+ # Resize image
31
+ img = img.resize(target_size)
32
+
33
+ # Convert to numpy array and normalize
34
+ img_array = np.array(img) / 255.0
35
+
36
+ # Add batch dimension
37
+ img_array = np.expand_dims(img_array, axis=0)
38
+
39
+ return img_array
40
+ except Exception as e:
41
+ print(f"Error preprocessing image: {e}")
42
+ return None
43
+
44
+ def predict_disease(model, image_array):
45
+ """
46
+ Make prediction on preprocessed image
47
+ """
48
+ try:
49
+ # Make prediction
50
+ prediction = model.predict(image_array)
51
+ predicted_class = np.argmax(prediction[0])
52
+ confidence = prediction[0][predicted_class]
53
+
54
+ return predicted_class, confidence, prediction[0]
55
+ except Exception as e:
56
+ print(f"Error making prediction: {e}")
57
+ return None, None, None
58
+
59
+ def get_class_name(class_index):
60
+ """
61
+ Get class name from class index
62
+ """
63
+ classes = [
64
+ "Apple___Apple_scab", "Apple___Black_rot", "Apple___Cedar_apple_rust", "Apple___healthy",
65
+ "Blueberry___healthy", "Cherry_(including_sour)___Powdery_mildew", "Cherry_(including_sour)___healthy",
66
+ "Corn_(maize)___Cercospora_leaf_spot Gray_leaf_spot", "Corn_(maize)___Common_rust_",
67
+ "Corn_(maize)___Northern_Leaf_Blight", "Corn_(maize)___healthy", "Grape___Black_rot",
68
+ "Grape___Esca_(Black_Measles)", "Grape___Leaf_blight_(Isariopsis_Leaf_Spot)", "Grape___healthy",
69
+ "Orange___Haunglongbing_(Citrus_greening)", "Peach___Bacterial_spot", "Peach___healthy",
70
+ "Pepper,_bell___Bacterial_spot", "Pepper,_bell___healthy", "Potato___Early_blight",
71
+ "Potato___Late_blight", "Potato___healthy", "Raspberry___healthy", "Soybean___healthy",
72
+ "Squash___Powdery_mildew", "Strawberry___Leaf_scorch", "Strawberry___healthy",
73
+ "Tomato___Bacterial_spot", "Tomato___Early_blight", "Tomato___Late_blight", "Tomato___Leaf_Mold",
74
+ "Tomato___Septoria_leaf_spot", "Tomato___Spider_mites Two-spotted_spider_mite",
75
+ "Tomato___Target_Spot", "Tomato___Tomato_Yellow_Leaf_Curl_Virus", "Tomato___Tomato_mosaic_virus",
76
+ "Tomato___healthy"
77
+ ]
78
+
79
+ if 0 <= class_index < len(classes):
80
+ return classes[class_index]
81
+ else:
82
+ return "Unknown"
83
+
84
+ def main():
85
+ """
86
+ Main function to demonstrate model usage
87
+ """
88
+ # Model path (update this path to your model location)
89
+ model_path = "Pretrained_model.h5"
90
+
91
+ # Check if model exists
92
+ if not os.path.exists(model_path):
93
+ print(f"Model file not found at: {model_path}")
94
+ print("Please ensure the model file is in the current directory or update the path.")
95
+ return
96
+
97
+ # Load model
98
+ model = load_model(model_path)
99
+ if model is None:
100
+ return
101
+
102
+ # Example usage with a sample image
103
+ # Replace 'sample_image.jpg' with your actual image path
104
+ sample_image_path = "sample_image.jpg"
105
+
106
+ if os.path.exists(sample_image_path):
107
+ # Preprocess image
108
+ image_array = preprocess_image(sample_image_path)
109
+ if image_array is None:
110
+ return
111
+
112
+ # Make prediction
113
+ predicted_class, confidence, all_predictions = predict_disease(model, image_array)
114
+
115
+ if predicted_class is not None:
116
+ class_name = get_class_name(predicted_class)
117
+ print(f"\nPrediction Results:")
118
+ print(f"Predicted Class: {class_name}")
119
+ print(f"Confidence: {confidence:.2%}")
120
+ print(f"Class Index: {predicted_class}")
121
+
122
+ # Show top 3 predictions
123
+ top_3_indices = np.argsort(all_predictions)[-3:][::-1]
124
+ print(f"\nTop 3 Predictions:")
125
+ for i, idx in enumerate(top_3_indices):
126
+ class_name = get_class_name(idx)
127
+ confidence = all_predictions[idx]
128
+ print(f"{i+1}. {class_name}: {confidence:.2%}")
129
+ else:
130
+ print(f"Sample image not found at: {sample_image_path}")
131
+ print("Please provide a valid image path to test the model.")
132
+
133
+ if __name__ == "__main__":
134
+ main()
plant-diseases-inceptionresnet.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ tensorflow>=2.8.0
2
+ numpy>=1.21.0
3
+ Pillow>=8.0.0
4
+ huggingface_hub>=0.10.0