Kennedy wambugu
commited on
Update README.md
Browse files
README.md
CHANGED
@@ -82,54 +82,18 @@ Users should evaluate the model on their specific crops and farming conditions.
|
|
82 |
import matplotlib.pyplot as plt
|
83 |
from PIL import Image, UnidentifiedImageError
|
84 |
from transformers import ViTFeatureExtractor, ViTForImageClassification
|
85 |
-
|
86 |
-
label2id= {'Corn___Common_Rust': '0',
|
87 |
-
'Corn___Gray_Leaf_Spot': '1',
|
88 |
-
'Corn___Healthy': '2',
|
89 |
-
'Corn___Leaf_Blight': '3',
|
90 |
-
'Invalid': '4',
|
91 |
-
'Potato___Early_Blight': '5',
|
92 |
-
'Potato___Healthy': '6',
|
93 |
-
'Potato___Late_Blight': '7',
|
94 |
-
'Rice___Brown_Spot': '8',
|
95 |
-
'Rice___Healthy': '9',
|
96 |
-
'Rice___Hispa': '10',
|
97 |
-
'Rice___Leaf_Blast': '11',
|
98 |
-
'Wheat___Brown_Rust': '12',
|
99 |
-
'Wheat___Healthy': '13',
|
100 |
-
'Wheat___Yellow_Rust': '14'},
|
101 |
-
id2label = {'0': 'Corn___Common_Rust',
|
102 |
-
'1': 'Corn___Gray_Leaf_Spot',
|
103 |
-
'2': 'Corn___Healthy',
|
104 |
-
'3': 'Corn___Leaf_Blight',
|
105 |
-
'4': 'Invalid',
|
106 |
-
'5': 'Potato___Early_Blight',
|
107 |
-
'6': 'Potato___Healthy',
|
108 |
-
'7': 'Potato___Late_Blight',
|
109 |
-
'8': 'Rice___Brown_Spot',
|
110 |
-
'9': 'Rice___Healthy',
|
111 |
-
'10': 'Rice___Hispa',
|
112 |
-
'11': 'Rice___Leaf_Blast',
|
113 |
-
'12': 'Wheat___Brown_Rust',
|
114 |
-
'13': 'Wheat___Healthy',
|
115 |
-
'14': 'Wheat___Yellow_Rust'}
|
116 |
-
|
117 |
-
feature_extractor = ViTFeatureExtractor.from_pretrained('WinKawaks/vit-tiny-patch16-224')
|
118 |
model = ViTForImageClassification.from_pretrained(
|
119 |
'wambugu1738/crop_leaf_diseases_vit',
|
120 |
-
num_labels=15,
|
121 |
-
label2id=label2id,
|
122 |
-
id2label=id2label,
|
123 |
ignore_mismatched_sizes=True
|
124 |
)
|
125 |
-
|
126 |
from PIL import Image
|
127 |
-
image = Image.open('
|
128 |
inputs = feature_extractor(images=image, return_tensors="pt")
|
129 |
outputs = model(**inputs)
|
130 |
logits = outputs.logits
|
131 |
predicted_class_idx = logits.argmax(-1).item()
|
132 |
-
print("Predicted class:", model.config.id2label[
|
133 |
```
|
134 |
|
135 |
## Training Details
|
|
|
82 |
import matplotlib.pyplot as plt
|
83 |
from PIL import Image, UnidentifiedImageError
|
84 |
from transformers import ViTFeatureExtractor, ViTForImageClassification
|
85 |
+
feature_extractor = ViTFeatureExtractor.from_pretrained('wambugu1738/crop_leaf_diseases_vit')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
model = ViTForImageClassification.from_pretrained(
|
87 |
'wambugu1738/crop_leaf_diseases_vit',
|
|
|
|
|
|
|
88 |
ignore_mismatched_sizes=True
|
89 |
)
|
|
|
90 |
from PIL import Image
|
91 |
+
image = Image.open('<image_path>')
|
92 |
inputs = feature_extractor(images=image, return_tensors="pt")
|
93 |
outputs = model(**inputs)
|
94 |
logits = outputs.logits
|
95 |
predicted_class_idx = logits.argmax(-1).item()
|
96 |
+
print("Predicted class:", model.config.id2label[predicted_class_idx])
|
97 |
```
|
98 |
|
99 |
## Training Details
|