eligapris commited on
Commit
e49d654
1 Parent(s): 1892af7

Update README.md

Browse files

detailed prediction

Files changed (1) hide show
  1. README.md +61 -0
README.md CHANGED
@@ -73,6 +73,67 @@ predicted_class = list(class_names.keys())[prediction.argmax()]
73
  print(f"Predicted class: {predicted_class}")
74
  ```
75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  ### Training data
77
 
78
  The model was trained on a dataset derived from the PlantVillage and PlantDoc datasets, specifically curated for maize leaf diseases. The dataset consists of:
 
73
  print(f"Predicted class: {predicted_class}")
74
  ```
75
 
76
+
77
+ Here's a detailed output of model prediction:
78
+
79
+ ```python
80
+ import tensorflow as tf
81
+ from PIL import Image
82
+ import numpy as np
83
+ import json
84
+
85
+ import tensorflow as tf
86
+ from huggingface_hub import snapshot_download
87
+
88
+ # Download the entire model directory
89
+ model_dir = snapshot_download(repo_id="eligapris/maize-diseases-detection",
90
+ local_dir="path/to/model")
91
+
92
+ # Load the model
93
+ model = tf.saved_model.load('path/to/model')
94
+
95
+ # Now you can use the model for inference
96
+
97
+ # Load and preprocess the image
98
+ img = Image.open('/path/to/image.jpg')
99
+ img = img.resize((300, 300 * img.size[1] // img.size[0]))
100
+ img_array = np.array(img)[None]
101
+
102
+ # Make prediction
103
+ inp = tensorflow.constant(img_array, dtype='float32')
104
+ prediction = model(inp)[0].numpy()
105
+
106
+ # Load class names and details
107
+ with open('model/classes_detailed.json', 'r') as f:
108
+ data = json.load(f)
109
+
110
+ class_names = data['classes']
111
+ class_details = data['details']
112
+
113
+ # Get the predicted class
114
+ predicted_class = list(class_names.keys())[prediction.argmax()]
115
+ predicted_class_label = class_names[predicted_class]
116
+
117
+ print(f"Predicted class: {predicted_class} (Label: {predicted_class_label})")
118
+
119
+ # Print detailed information about the predicted class
120
+ if predicted_class in class_details:
121
+ details = class_details[predicted_class]
122
+ print("\nDetailed Information:")
123
+ for key, value in details.items():
124
+ if isinstance(value, list):
125
+ print(f"{key.capitalize()}:")
126
+ for item in value:
127
+ print(f" - {item}")
128
+ else:
129
+ print(f"{key.capitalize()}: {value}")
130
+
131
+ # Print general notes
132
+ print("\nGeneral Notes:")
133
+ for note in data['general_notes']:
134
+ print(f"- {note}")
135
+ ```
136
+
137
  ### Training data
138
 
139
  The model was trained on a dataset derived from the PlantVillage and PlantDoc datasets, specifically curated for maize leaf diseases. The dataset consists of: