Views
No views yet
Bacterial Leaf BlightBrown SpotHealthy Rice LeafLeaf BlastLeaf scaldNarrow Brown Leaf SpotRice HispaSheath Blight1import numpy as np, json
2from huggingface_hub import hf_hub_download
3from tensorflow.keras.models import load_model
4from tensorflow.keras.preprocessing import image
5from tensorflow.keras.applications.mobilenet_v2 import preprocess_input
6
7repo = "hirooshaweerasuriya/rice-leaf-disease-mobilenetv2"
8model = load_model(hf_hub_download(repo, "rice_disease_model.keras"))
9config = json.load(open(hf_hub_download(repo, "config.json")))
10labels = [config["id2label"][str(i)] for i in range(config["num_classes"])]
11
12img = image.load_img("leaf.jpg", target_size=(224, 224))
13x = preprocess_input(np.expand_dims(image.img_to_array(img), 0))
14
15probs = model.predict(x)[0]
16print(labels[int(probs.argmax())], f"{probs.max():.1%}")preprocess_input scales pixels to [-1, 1].
Using /255.0 instead will produce confident, wrong answers.include_top=Falseclass_weight| Metric | Value |
|---|---|
| Validation accuracy | 0.7604 |
| Validation loss | 0.7156 |
| Class | Val samples | Recall |
|---|---|---|
| Bacterial Leaf Blight | 107 | 80.37% |
| Brown Spot | 162 | 61.11% |
| Healthy Rice Leaf | 102 | 91.18% |
| Leaf Blast | 185 | 62.16% |
| Leaf scald | 112 | 70.54% |
| Narrow Brown Leaf Spot | 70 | 64.29% |
| Rice Hispa | 132 | 87.88% |
| Sheath Blight | 165 | 93.33% |
| File | Description |
|---|---|
rice_disease_model.keras | Keras 3 model |
saved_model/ | TensorFlow SavedModel |
model.tflite | Quantised TFLite build for mobile |
config.json | Labels, image size, preprocessing, metrics |
labels.txt | Class names in index order |