BrandonFors/Plant-Diseases-PlantVillage-Dataset
Viewer โข Updated โข 54.3k โข 364 โข 1
How to use VaigandlaHemanth/leaf-disease-clip-vit with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("image-classification", model="VaigandlaHemanth/leaf-disease-clip-vit")
pipe("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/parrots.png") # Load model directly
from transformers import AutoProcessor, AutoModelForImageClassification
processor = AutoProcessor.from_pretrained("VaigandlaHemanth/leaf-disease-clip-vit")
model = AutoModelForImageClassification.from_pretrained("VaigandlaHemanth/leaf-disease-clip-vit")CLIP ViT-B/32 with a 38-class classification head for plant leaf disease detection, trained on the PlantVillage Dataset.
CLIPForImageClassification (CLIP ViT-B/32 vision encoder + linear classification head)from transformers import CLIPForImageClassification, AutoImageProcessor
from PIL import Image
import torch
model = CLIPForImageClassification.from_pretrained("VaigandlaHemanth/leaf-disease-clip-vit")
processor = AutoImageProcessor.from_pretrained("VaigandlaHemanth/leaf-disease-clip-vit")
image = Image.open("leaf.jpg").convert("RGB")
inputs = processor(images=image, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
predicted_class = outputs.logits.argmax(-1).item()
label = model.config.id2label[str(predicted_class)]
print(f"Predicted: {label}")
| Plant | Diseases |
|---|---|
| Apple | Scab, Black Rot, Cedar Apple Rust, Healthy |
| Blueberry | Healthy |
| Cherry | Powdery Mildew, Healthy |
| Corn | Gray Leaf Spot, Common Rust, Northern Leaf Blight, Healthy |
| Grape | Black Rot, Esca, Leaf Blight, Healthy |
| Orange | Huanglongbing (Citrus Greening) |
| Peach | Bacterial Spot, Healthy |
| Pepper | Bacterial Spot, Healthy |
| Potato | Early Blight, Late Blight, Healthy |
| Raspberry | Healthy |
| Soybean | Healthy |
| Squash | Powdery Mildew |
| Strawberry | Leaf Scorch, Healthy |
| Tomato | Bacterial Spot, Early/Late Blight, Leaf Mold, Septoria, Spider Mites, Target Spot, TYLCV, Mosaic Virus, Healthy |
A complete training script is included in train.py. To fine-tune on GPU:
pip install transformers datasets torch torchvision scikit-learn accelerate
python train.py
Key hyperparameters (from paper):
Expected accuracy with full GPU training: >95% on PlantVillage test set.
Try the interactive demo: ๐ฟ Leaf Disease Detector Space
@article{dong2022clip,
title={CLIP Itself is a Strong Fine-tuner: Achieving 85.7% and 88.0% Top-1 Accuracy with ViT-B and ViT-L on ImageNet},
author={Dong, Xiaoyi and Bao, Jianmin and Zhang, Ting and Chen, Dongdong and Zhang, Weiming and Yuan, Lu and Chen, Dong and Wen, Fang and Yu, Nenghai},
journal={arXiv preprint arXiv:2212.06138},
year={2022}
}
Base model
openai/clip-vit-base-patch32