Create README.md
Browse filesResNet18 classifier that predicts one of four viewpoints (back, front, left_side, right_side) for frames showing Spotted Bowerbird individuals (images should be pre-processed to remove the background)
README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
base_model:
|
| 3 |
+
- microsoft/resnet-18
|
| 4 |
+
pipeline_tag: image-classification
|
| 5 |
+
tags:
|
| 6 |
+
- ecology
|
| 7 |
+
- birds
|
| 8 |
+
- posture
|
| 9 |
+
---
|
| 10 |
+
# Bowerbird viewpoint classifier (ResNet18)
|
| 11 |
+
|
| 12 |
+
- Task: classify each frame into one of four viewpoints:
|
| 13 |
+
`["back", "front", "left_side", "right_side"]`
|
| 14 |
+
- Base model: `torchvision.models.resnet18` with `weights="IMAGENET1K_V1"`
|
| 15 |
+
- Input size: 224 × 224 (after cropping)
|
| 16 |
+
- Preprocessing (training/eval):
|
| 17 |
+
- Resize to 256 px on the shorter side
|
| 18 |
+
- Train: RandomResizedCrop(224), RandomRotation(7°), ColorJitter
|
| 19 |
+
- Eval: CenterCrop(224)
|
| 20 |
+
- Normalization:
|
| 21 |
+
- mean = [0.485, 0.456, 0.406]
|
| 22 |
+
- std = [0.229, 0.224, 0.225]
|
| 23 |
+
- Checkpoint file: `Bbird_viewpoint_classifier.pth`
|
| 24 |
+
- The checkpoint stores a **PyTorch `state_dict`** for ResNet18 with a final
|
| 25 |
+
linear layer of 4 outputs (one per viewpoint class).
|
| 26 |
+
|
| 27 |
+
> This model is **not** generic. It is specific to the four viewpoint classes
|
| 28 |
+
> listed above. The classification head must have 4 outputs, in the same
|
| 29 |
+
> class order: `back`, `front`, `left_side`, `right_side`.
|
| 30 |
+
|
| 31 |
+
## Usage
|
| 32 |
+
|
| 33 |
+
```python
|
| 34 |
+
import torch
|
| 35 |
+
from torch import nn
|
| 36 |
+
from torchvision.models import resnet18
|
| 37 |
+
from huggingface_hub import hf_hub_download
|
| 38 |
+
|
| 39 |
+
# Replace this with the actual repo id on the Hub if different
|
| 40 |
+
repo_id = "sarequi/bowerbird-viewpoint-classifier"
|
| 41 |
+
|
| 42 |
+
# Download checkpoint
|
| 43 |
+
ckpt_path = hf_hub_download(
|
| 44 |
+
repo_id=repo_id,
|
| 45 |
+
filename="Bbird_viewpoint_classifier.pth",
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
# Rebuild the model architecture exactly as in training
|
| 49 |
+
NUM_CLASSES = 4
|
| 50 |
+
model = resnet18(weights="IMAGENET1K_V1")
|
| 51 |
+
model.fc = nn.Linear(model.fc.in_features, NUM_CLASSES)
|
| 52 |
+
|
| 53 |
+
# Load weights
|
| 54 |
+
state_dict = torch.load(ckpt_path, map_location="cpu")
|
| 55 |
+
model.load_state_dict(state_dict)
|
| 56 |
+
model.eval()
|
| 57 |
+
|
| 58 |
+
VIEWPOINT_CLASSES = ["back", "front", "left_side", "right_side"]
|