Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# π§ Beans-Image-Classification-AI-Model
|
2 |
+
|
3 |
+
A fine-tuned image classification model trained on the Beans dataset with 3 classes: angular_leaf_spot, bean_rust, and healthy. This model is built using Hugging Face Transformers and the ViT (Vision Transformer) architecture and is suitable for educational use, plant disease classification tasks, and image classification experiments.
|
4 |
+
|
5 |
+
---
|
6 |
+
|
7 |
+
|
8 |
+
## β¨ Model Highlights
|
9 |
+
|
10 |
+
- π Base Model: google/vit-base-patch16-224-in21k
|
11 |
+
- π Fine-tuned: Beans dataset
|
12 |
+
- πΏ Classes: angular_leaf_spot, bean_rust, healthy
|
13 |
+
- π§ Framework: Hugging Face Transformers + PyTorch
|
14 |
+
- π¦ Preprocessing: AutoImageProcessor from Transformers
|
15 |
+
|
16 |
+
---
|
17 |
+
|
18 |
+
## π§ Intended Uses
|
19 |
+
|
20 |
+
- β
Educational tools for training and evaluation in agriculture and plant disease detection
|
21 |
+
- β
Benchmarking vision transformer models on small datasets
|
22 |
+
- β
Demonstration of fine-tuning workflows with Hugging Face
|
23 |
+
|
24 |
+
---
|
25 |
+
|
26 |
+
## π« Limitations
|
27 |
+
|
28 |
+
- β Not suitable for real-world diagnosis in agriculture without further domain validation
|
29 |
+
- β Not robust to significant background noise or occlusion in images
|
30 |
+
- β Trained on small dataset, may not generalize beyond bean leaf diseases
|
31 |
+
|
32 |
+
---
|
33 |
+
|
34 |
+
π Input & Output
|
35 |
+
|
36 |
+
- Input: RGB image of a bean leaf (expected size 224x224)
|
37 |
+
- Output: Predicted class label β angular_leaf_spot, bean_rust, or healthy
|
38 |
+
|
39 |
+
---
|
40 |
+
|
41 |
+
## ποΈββοΈ Training Details
|
42 |
+
|
43 |
+
| Attribute | Value |
|
44 |
+
|--------------------|----------------------------------|
|
45 |
+
| Base Model |`google/vit-base-patch16-224-in21k|
|
46 |
+
| Dataset |Beans Dataset (train/val/test) |
|
47 |
+
| Task Type | Image Classification |
|
48 |
+
| Image Size | 224 Γ 224 |
|
49 |
+
| Epochs | 3 |
|
50 |
+
| Batch Size | 16 |
|
51 |
+
| Optimizer | AdamW |
|
52 |
+
| Loss Function | CrossEntropyLoss |
|
53 |
+
| Framework | PyTorch + Transformers |
|
54 |
+
| Hardware | CUDA-enabled GPU |
|
55 |
+
|
56 |
+
---
|
57 |
+
|
58 |
+
## π Evaluation Metrics
|
59 |
+
|
60 |
+
|
61 |
+
| Metric | Score |
|
62 |
+
| ----------------------------------------------- | ----- |
|
63 |
+
| Accuracy | 0.98 |
|
64 |
+
| F1-Score | 0.99 |
|
65 |
+
| Precision | 0.98 |
|
66 |
+
| Recall | 0.99 |
|
67 |
+
|
68 |
+
|
69 |
+
---
|
70 |
+
|
71 |
+
---
|
72 |
+
π Usage
|
73 |
+
```python
|
74 |
+
from transformers import AutoImageProcessor, AutoModelForImageClassification
|
75 |
+
from PIL import Image
|
76 |
+
import torch
|
77 |
+
|
78 |
+
model_name = "AventIQ-AI/Beans-Image-Classification-AI-Model"
|
79 |
+
|
80 |
+
processor = AutoImageProcessor.from_pretrained(model_name)
|
81 |
+
model = AutoModelForImageClassification.from_pretrained(model_name)
|
82 |
+
model.eval()
|
83 |
+
|
84 |
+
def predict(image_path):
|
85 |
+
image = Image.open(image_path).convert("RGB")
|
86 |
+
inputs = processor(images=image, return_tensors="pt").to(model.device)
|
87 |
+
with torch.no_grad():
|
88 |
+
outputs = model(**inputs)
|
89 |
+
preds = torch.argmax(outputs.logits, dim=1)
|
90 |
+
return model.config.id2label[preds.item()]
|
91 |
+
|
92 |
+
# Example
|
93 |
+
print(predict("example_leaf.jpg"))
|
94 |
+
|
95 |
+
|
96 |
+
```
|
97 |
+
---
|
98 |
+
|
99 |
+
- π§© Quantization
|
100 |
+
- Post-training static quantization applied using PyTorch to reduce model size and accelerate inference on edge devices.
|
101 |
+
|
102 |
+
----
|
103 |
+
|
104 |
+
π Repository Structure
|
105 |
+
```
|
106 |
+
.
|
107 |
+
beans-vit-finetuned/
|
108 |
+
βββ config.json β
Model architecture & config
|
109 |
+
βββ pytorch_model.bin β
Model weights
|
110 |
+
βββ preprocessor_config.json β
Image processor config
|
111 |
+
βββ special_tokens_map.json β
(Auto-generated, not critical for ViT)
|
112 |
+
βββ training_args.bin β
Training metadata
|
113 |
+
βββ README.md β
Model card
|
114 |
+
|
115 |
+
```
|
116 |
+
---
|
117 |
+
π€ Contributing
|
118 |
+
|
119 |
+
Open to improvements and feedback! Feel free to submit a pull request or open an issue if you find any bugs or want to enhance the model.
|
120 |
+
|
121 |
+
|