Insect Classification: Vision Transformer (ViT) Model
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.
Training Hardware & Specs
- Compute: NVIDIA A100 Tensor Core GPU (SXM4 40GB)
- Total Training Steps: 16,600 iterations (20 full epochs)
- Training Time: 31 minutes 25 seconds
- Base Architecture: Vision Transformer Base (
vit-base-patch16-224) - Image Resolution: 224 x 224 px
Evaluation Benchmark & Training History
| 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% |
Top Metrics Achieved:
- Final Top-1 Accuracy: 98.51%
- Macro F1-Score: 98.58%
- Minimal Training Loss: 0.000100
Supported Taxa / Classes (21 Classes)
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
Quick Inference Usage
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}%)")
- Downloads last month
- 11
Evaluation results
- Accuracy on Specifly 50K Insect Datasetself-reported0.985
- F1-Score on Specifly 50K Insect Datasetself-reported0.986