Instructions to use hirooshaweerasuriya/rice-leaf-disease-mobilenetv2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use hirooshaweerasuriya/rice-leaf-disease-mobilenetv2 with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://hirooshaweerasuriya/rice-leaf-disease-mobilenetv2") - Notebooks
- Google Colab
- Kaggle
Rice Leaf Disease Detection (MobileNetV2)
Fine-tuned MobileNetV2 that classifies rice (paddy) leaf images into 8 categories. Validation accuracy: 76.04%.
Classes
Bacterial Leaf BlightBrown SpotHealthy Rice LeafLeaf BlastLeaf scaldNarrow Brown Leaf SpotRice HispaSheath Blight
Label order matters โ index i of the softmax output corresponds to item i above.
Usage
import numpy as np, json
from huggingface_hub import hf_hub_download
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing import image
from tensorflow.keras.applications.mobilenet_v2 import preprocess_input
repo = "hirooshaweerasuriya/rice-leaf-disease-mobilenetv2"
model = load_model(hf_hub_download(repo, "rice_disease_model.keras"))
config = json.load(open(hf_hub_download(repo, "config.json")))
labels = [config["id2label"][str(i)] for i in range(config["num_classes"])]
img = image.load_img("leaf.jpg", target_size=(224, 224))
x = preprocess_input(np.expand_dims(image.img_to_array(img), 0))
probs = model.predict(x)[0]
print(labels[int(probs.argmax())], f"{probs.max():.1%}")
Preprocessing must match training: preprocess_input scales pixels to [-1, 1].
Using /255.0 instead will produce confident, wrong answers.
Training
- Base: MobileNetV2, ImageNet weights,
include_top=False - Head: GlobalAveragePooling2D โ Dropout(0.3) โ Dense(128, relu) โ Dropout(0.2) โ Dense(8, softmax)
- Stage 1: backbone frozen, Adam lr=1e-3, 8 epochs
- Stage 2: top 30 layers unfrozen (BatchNorm kept frozen), Adam lr=1e-5, 6 epochs
- Augmentation: rotation 25ยฐ, zoom 0.2, shifts 0.1, shear 0.1, horizontal flip, brightness 0.8โ1.2
- Class imbalance handled with balanced
class_weight - Data: anshulm257/rice-disease-dataset, 80/20 split
- Trained on a Kaggle free-tier GPU notebook
Results
| 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% |
Limitations
- Trained on a single curated dataset; field photos with varied lighting, backgrounds and phone cameras will be harder.
- The dataset appears pre-augmented, so near-duplicates may span the train/val split โ real-world accuracy is likely below the number above.
- Always returns one of the 8 classes; a photo of something else still gets a confident label. Threshold on max probability if that matters.
- A decision-support tool, not a substitute for agronomist diagnosis.
Files
| 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 |
- Downloads last month
- 190