Downloads · 30 days
7
26% of all-time downloads
Mustafa5645344/insect-detection-vit
insect-detection-vit is a image classification model from Mustafa5645344. Use it when you need a label for an image. The card lists the license as mit.
This model is a high-accuracy fine-tuned Vision Transformer (ViT) (google/vit-base-patch16-224-in21k backbone) trained to classify 21 distinct agricultural insect pest and beneficial species.
Downloads · 30 days
7
26% of all-time downloads
All-time downloads
27
Public
Parameters
85.8M
343 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors343 MB · 100%
From the Hugging Face model README
This model is a high-accuracy fine-tuned Vision Transformer (ViT) (google/vit-base-patch16-224-in21k backbone) trained to classify 21 distinct agricultural insect pest and beneficial species.
vit-base-patch16-224)| Epoch | Training Loss | Validation Loss | Accuracy | F1-Score |
|---|---|---|---|---|
| 1 | 0.3389 | 0.3206 | 97.41% | 97.57% |
| 2 | 0.1076 | 0.1481 | 97.77% | 97.91% |
| 3 | 0.0486 | 0.1073 | 97.83% | 97.95% |
| 4 | 0.0252 | 0.0999 | 98.13% | 98.18% |
| 5 | 0.0167 | 0.0784 | 98.45% | 98.51% |
| 10 | 0.0065 | 0.1190 | 98.03% | 98.12% |
| 15 | 0.0003 | 0.1093 | 98.42% | 98.50% |
| 19 | 0.0001 | 0.1151 | 98.51% | 98.59% |
| 20 (Final) | 0.0001 | 0.1153 | 98.51% | 98.58% |
ant, aphid, bees, butterfly, caterpillar, cicada, dragonfly, grasshopper, green_lacewing, ladybug, leafhopper, mantis, mole_cricket, planthopper, rhino_beetle, rice_bug, spider, stem_borer, stink_bug, undefined, weevil
from transformers import AutoImageProcessor, AutoModelForImageClassification
from PIL import Image
import torch
model_id = "Mustafa5645344/insect-detection-vit"
# Load image processor & model
processor = AutoImageProcessor.from_pretrained("google/vit-base-patch16-224")
model = AutoModelForImageClassification.from_pretrained(model_id)
image = Image.open("insect_sample.jpg")
inputs = processor(images=image, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
probs = torch.softmax(outputs.logits, dim=-1)
predicted_idx = outputs.logits.argmax(-1).item()
predicted_label = model.config.id2label[str(predicted_idx)]
confidence = probs[0][predicted_idx].item()
print(f"Species: {predicted_label} (Confidence: {confidence*100:.2f}%)")