Views
No views yet

Rice-Leaf-Disease is an image classification model fine-tuned from google/siglip2-base-patch16-224 for detecting and categorizing diseases in rice leaves. It is built using the SiglipForImageClassification architecture and helps in early identification of plant diseases for better crop management.
1Classification Report:
2 precision recall f1-score support
3
4Bacterialblight 0.8853 0.9596 0.9210 1585
5 Blast 0.9271 0.8472 0.8853 1440
6 Brownspot 0.9746 0.9369 0.9554 1600
7 Healthy 1.0000 1.0000 1.0000 1488
8 Tungro 0.9589 0.9977 0.9779 1308
9
10 accuracy 0.9477 7421
11 macro avg 0.9492 0.9483 0.9479 7421
12 weighted avg 0.9486 0.9477 0.9474 7421
!pip install -q transformers torch pillow gradio1import gradio as gr
2from transformers import AutoImageProcessor, SiglipForImageClassification
3from transformers.image_utils import load_image
4from PIL import Image
5import torch
6
7# Load model and processor
8model_name = "prithivMLmods/Rice-Leaf-Disease"
9model = SiglipForImageClassification.from_pretrained(model_name)
10processor = AutoImageProcessor.from_pretrained(model_name)
11
12def classify_leaf_disease(image):
13 """Predicts the disease type in a rice leaf image."""
14 image = Image.fromarray(image).convert("RGB")
15 inputs = processor(images=image, return_tensors="pt")
16
17 with torch.no_grad():
18 outputs = model(**inputs)
19 logits = outputs.logits
20 probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
21
22 labels = {
23 "0": "Bacterial Blight",
24 "1": "Blast",
25 "2": "Brown Spot",
26 "3": "Healthy",
27 "4": "Tungro"
28 }
29 predictions = {labels[str(i)]: round(probs[i], 3) for i in range(len(probs))}
30
31 return predictions
32
33# Create Gradio interface
34iface = gr.Interface(
35 fn=classify_leaf_disease,
36 inputs=gr.Image(type="numpy"),
37 outputs=gr.Label(label="Prediction Scores"),
38 title="Rice Leaf Disease Classification 🌾",
39 description="Upload an image of a rice leaf to identify if it is healthy or affected by diseases like Bacterial Blight, Blast, Brown Spot, or Tungro."
40)
41
42# Launch the app
43if __name__ == "__main__":
44 iface.launch()