Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- image-classification
|
| 5 |
+
- pytorch
|
| 6 |
+
- cats
|
| 7 |
+
- efficientnet
|
| 8 |
+
library_name: pytorch
|
| 9 |
+
pipeline_tag: image-classification
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# Which Cat? - Lucy vs Madelaine Classifier
|
| 13 |
+
|
| 14 |
+
A fine-tuned EfficientNet-B0 model that distinguishes between two cats: Lucy and Madelaine.
|
| 15 |
+
|
| 16 |
+
## Model Details
|
| 17 |
+
|
| 18 |
+
- **Base Model**: EfficientNet-B0 (pretrained on ImageNet)
|
| 19 |
+
- **Task**: Binary image classification
|
| 20 |
+
- **Classes**: `lucy`, `madelaine`
|
| 21 |
+
- **Training Data**: ~190 personal photos
|
| 22 |
+
- **Validation Accuracy**: 90%
|
| 23 |
+
|
| 24 |
+
## Usage
|
| 25 |
+
|
| 26 |
+
```python
|
| 27 |
+
import torch
|
| 28 |
+
import torch.nn as nn
|
| 29 |
+
from torchvision import transforms, models
|
| 30 |
+
from PIL import Image
|
| 31 |
+
from huggingface_hub import hf_hub_download
|
| 32 |
+
|
| 33 |
+
# Download model
|
| 34 |
+
model_path = hf_hub_download(repo_id="khasinski/which-cat", filename="cat_classifier.pth")
|
| 35 |
+
|
| 36 |
+
# Load model
|
| 37 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 38 |
+
checkpoint = torch.load(model_path, map_location=device, weights_only=False)
|
| 39 |
+
|
| 40 |
+
model = models.efficientnet_b0(weights=None)
|
| 41 |
+
model.classifier = nn.Sequential(
|
| 42 |
+
nn.Dropout(p=0.3),
|
| 43 |
+
nn.Linear(1280, 2)
|
| 44 |
+
)
|
| 45 |
+
model.load_state_dict(checkpoint['model_state_dict'])
|
| 46 |
+
model.to(device)
|
| 47 |
+
model.eval()
|
| 48 |
+
|
| 49 |
+
# Class mapping
|
| 50 |
+
idx_to_class = {v: k for k, v in checkpoint['class_to_idx'].items()}
|
| 51 |
+
|
| 52 |
+
# Predict
|
| 53 |
+
transform = transforms.Compose([
|
| 54 |
+
transforms.Resize((224, 224)),
|
| 55 |
+
transforms.ToTensor(),
|
| 56 |
+
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
|
| 57 |
+
])
|
| 58 |
+
|
| 59 |
+
image = Image.open("your_cat.jpg").convert('RGB')
|
| 60 |
+
tensor = transform(image).unsqueeze(0).to(device)
|
| 61 |
+
|
| 62 |
+
with torch.no_grad():
|
| 63 |
+
probs = torch.softmax(model(tensor), dim=1)[0]
|
| 64 |
+
pred_idx = probs.argmax().item()
|
| 65 |
+
|
| 66 |
+
print(f"Prediction: {idx_to_class[pred_idx]} ({probs[pred_idx]:.1%})")
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
## Training
|
| 70 |
+
|
| 71 |
+
Trained using transfer learning with:
|
| 72 |
+
- Data augmentation (flips, rotations, color jitter)
|
| 73 |
+
- Weighted random sampling for class balance
|
| 74 |
+
- AdamW optimizer with learning rate scheduling
|
| 75 |
+
- 20 epochs on Apple MPS
|
| 76 |
+
|
| 77 |
+
## Limitations
|
| 78 |
+
|
| 79 |
+
This model is trained specifically on Lucy and Madelaine. It will not generalize to other cats - it will simply classify any cat image as one of the two.
|