Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,3 +1,118 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: mit
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- image-classification
|
| 5 |
+
- pytorch
|
| 6 |
+
- convnext
|
| 7 |
+
- birds
|
| 8 |
+
- computer-vision
|
| 9 |
+
datasets:
|
| 10 |
+
- CUB-200-2011
|
| 11 |
+
metrics:
|
| 12 |
+
- accuracy
|
| 13 |
+
library_name: pytorch
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
# Bird Species Classification - ConvNeXt-Base
|
| 17 |
+
|
| 18 |
+
## Model Description
|
| 19 |
+
|
| 20 |
+
This model classifies 200 bird species using ConvNeXt-Base architecture with transfer learning.
|
| 21 |
+
|
| 22 |
+
## Performance
|
| 23 |
+
|
| 24 |
+
- **Test Accuracy**: 83.64%
|
| 25 |
+
- **Average Per-Class Accuracy**: 83.29%
|
| 26 |
+
- **Architecture**: ConvNeXt-Base (87M parameters)
|
| 27 |
+
- **Dataset**: CUB-200-2011 (200 bird species)
|
| 28 |
+
|
| 29 |
+
## Training Details
|
| 30 |
+
|
| 31 |
+
### Model Architecture
|
| 32 |
+
- **Base Model**: ConvNeXt-Base pretrained on ImageNet-1K
|
| 33 |
+
- **Classifier**: Custom 2-layer classifier with dropout
|
| 34 |
+
- **Input Size**: 224x224 RGB images
|
| 35 |
+
|
| 36 |
+
### Training Strategy
|
| 37 |
+
- **Phase 1** (40 epochs): Frozen backbone, train classifier only
|
| 38 |
+
- Learning Rate: 0.001
|
| 39 |
+
- Batch Size: 32
|
| 40 |
+
|
| 41 |
+
- **Phase 2** (20 epochs): Full fine-tuning
|
| 42 |
+
- Learning Rate: 0.0001
|
| 43 |
+
- Batch Size: 32
|
| 44 |
+
|
| 45 |
+
### Regularization
|
| 46 |
+
- Dropout: 0.6, 0.5
|
| 47 |
+
- Label Smoothing: 0.2
|
| 48 |
+
- Weight Decay: 0.005
|
| 49 |
+
- Data Augmentation: rotation, flip, color jitter, random erasing
|
| 50 |
+
|
| 51 |
+
## Usage
|
| 52 |
+
|
| 53 |
+
```python
|
| 54 |
+
import torch
|
| 55 |
+
import torch.nn as nn
|
| 56 |
+
from torchvision import models, transforms
|
| 57 |
+
from PIL import Image
|
| 58 |
+
|
| 59 |
+
# Load model
|
| 60 |
+
model = models.convnext_base(weights=None)
|
| 61 |
+
num_features = model.classifier[2].in_features
|
| 62 |
+
model.classifier[2] = nn.Sequential(
|
| 63 |
+
nn.Dropout(0.6),
|
| 64 |
+
nn.Linear(num_features, 1024),
|
| 65 |
+
nn.ReLU(),
|
| 66 |
+
nn.Dropout(0.5),
|
| 67 |
+
nn.Linear(1024, 200)
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
# Load weights
|
| 71 |
+
model.load_state_dict(torch.load('final_model.pth', map_location='cpu'))
|
| 72 |
+
model.eval()
|
| 73 |
+
|
| 74 |
+
# Preprocessing
|
| 75 |
+
transform = transforms.Compose([
|
| 76 |
+
transforms.Resize((224, 224)),
|
| 77 |
+
transforms.ToTensor(),
|
| 78 |
+
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
|
| 79 |
+
])
|
| 80 |
+
|
| 81 |
+
# Predict
|
| 82 |
+
image = Image.open('bird.jpg').convert('RGB')
|
| 83 |
+
image_tensor = transform(image).unsqueeze(0)
|
| 84 |
+
|
| 85 |
+
with torch.no_grad():
|
| 86 |
+
outputs = model(image_tensor)
|
| 87 |
+
probabilities = torch.nn.functional.softmax(outputs[0], dim=0)
|
| 88 |
+
top5_prob, top5_indices = torch.topk(probabilities, 5)
|
| 89 |
+
|
| 90 |
+
print("Top 5 Predictions:")
|
| 91 |
+
for prob, idx in zip(top5_prob, top5_indices):
|
| 92 |
+
print(f"Class {idx}: {prob.item()*100:.2f}%")
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
## Try it out!
|
| 96 |
+
|
| 97 |
+
Try the live demo: [Bird Species Classifier](https://huggingface.co/spaces/AshProg/AppliedMachineLearning_BirdClassifierInterface)
|
| 98 |
+
|
| 99 |
+
## Model Files
|
| 100 |
+
|
| 101 |
+
- `final_model.pth` (1.06 GB): Full model weights
|
| 102 |
+
|
| 103 |
+
## Citation
|
| 104 |
+
|
| 105 |
+
Dataset: CUB-200-2011
|
| 106 |
+
```
|
| 107 |
+
@techreport{WahCUB_200_2011,
|
| 108 |
+
Title = {{The Caltech-UCSD Birds-200-2011 Dataset}},
|
| 109 |
+
Author = {Wah, C. and Branson, S. and Welinder, P. and Perona, P. and Belongie, S.},
|
| 110 |
+
Year = {2011},
|
| 111 |
+
Institution = {California Institute of Technology},
|
| 112 |
+
Number = {CNS-TR-2011-001}
|
| 113 |
+
}
|
| 114 |
+
```
|
| 115 |
+
|
| 116 |
+
## Contact
|
| 117 |
+
|
| 118 |
+
For questions or issues, please open an issue on the Space repository.
|