Views
No views yet
CLIPForImageClassification (CLIP ViT-B/32 vision encoder + linear classification head)1from transformers import CLIPForImageClassification, AutoImageProcessor
2from PIL import Image
3import torch
4
5model = CLIPForImageClassification.from_pretrained("VaigandlaHemanth/leaf-disease-clip-vit")
6processor = AutoImageProcessor.from_pretrained("VaigandlaHemanth/leaf-disease-clip-vit")
7
8image = Image.open("leaf.jpg").convert("RGB")
9inputs = processor(images=image, return_tensors="pt")
10
11with torch.no_grad():
12 outputs = model(**inputs)
13
14predicted_class = outputs.logits.argmax(-1).item()
15label = model.config.id2label[str(predicted_class)]
16print(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 |
train.py. To fine-tune on GPU:1pip install transformers datasets torch torchvision scikit-learn accelerate
2python train.py1@article{dong2022clip,
2 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},
3 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},
4 journal={arXiv preprint arXiv:2212.06138},
5 year={2022}
6}