Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,87 @@
|
|
| 1 |
---
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- image-classification
|
| 5 |
+
- pytorch
|
| 6 |
+
- mobilenet
|
| 7 |
+
- fashion
|
| 8 |
+
- abaya
|
| 9 |
+
- thobe
|
| 10 |
+
pipeline_tag: image-classification
|
| 11 |
+
library_name: pytorch
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
# Abaya & Thobe Image Classifier
|
| 15 |
+
|
| 16 |
+
A fine-tuned **MobileNetV2** model that classifies garment images as **Abaya** or **Thobe**.
|
| 17 |
+
|
| 18 |
+
## Model Details
|
| 19 |
+
|
| 20 |
+
| Property | Value |
|
| 21 |
+
|----------|-------|
|
| 22 |
+
| Base model | MobileNetV2 (ImageNet pretrained) |
|
| 23 |
+
| Task | Binary Image Classification |
|
| 24 |
+
| Framework | PyTorch |
|
| 25 |
+
| Input size | 224 × 224 RGB |
|
| 26 |
+
| Output classes | Abaya, Thobe |
|
| 27 |
+
|
| 28 |
+
## Architecture
|
| 29 |
+
|
| 30 |
+
The backbone (MobileNetV2) was frozen. Only the custom classifier head was trained:
|
| 31 |
+
```
|
| 32 |
+
Dropout(0.3) → Linear(1280 → 128) → ReLU → Dropout(0.2) → Linear(128 → 2)
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
## Training
|
| 36 |
+
|
| 37 |
+
| Setting | Value |
|
| 38 |
+
|---------|-------|
|
| 39 |
+
| Epochs | 15 |
|
| 40 |
+
| Optimizer | Adam |
|
| 41 |
+
| Learning rate | 1e-3 |
|
| 42 |
+
| Weight decay | 1e-4 |
|
| 43 |
+
| Loss | CrossEntropyLoss |
|
| 44 |
+
| Dataset | ~500 crawled garment images (Abaya & Thobe) |
|
| 45 |
+
|
| 46 |
+
## Labels
|
| 47 |
+
|
| 48 |
+
| ID | Label |
|
| 49 |
+
|----|-------|
|
| 50 |
+
| 0 | abaya |
|
| 51 |
+
| 1 | thobe |
|
| 52 |
+
|
| 53 |
+
## Usage
|
| 54 |
+
```python
|
| 55 |
+
import torch
|
| 56 |
+
import torch.nn as nn
|
| 57 |
+
import torchvision.models as models
|
| 58 |
+
import torchvision.transforms as transforms
|
| 59 |
+
from huggingface_hub import hf_hub_download
|
| 60 |
+
from PIL import Image
|
| 61 |
+
|
| 62 |
+
# Load model
|
| 63 |
+
weights = hf_hub_download("Resham2987/abaya-and-thobes-classifier", "pytorch_model.bin")
|
| 64 |
+
|
| 65 |
+
model = models.mobilenet_v2(weights=None)
|
| 66 |
+
model.classifier = nn.Sequential(
|
| 67 |
+
nn.Dropout(0.3), nn.Linear(1280, 128),
|
| 68 |
+
nn.ReLU(), nn.Dropout(0.2), nn.Linear(128, 2)
|
| 69 |
+
)
|
| 70 |
+
model.load_state_dict(torch.load(weights, map_location="cpu"))
|
| 71 |
+
model.eval()
|
| 72 |
+
|
| 73 |
+
# Preprocess
|
| 74 |
+
tf = transforms.Compose([
|
| 75 |
+
transforms.Resize((224, 224)),
|
| 76 |
+
transforms.ToTensor(),
|
| 77 |
+
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),
|
| 78 |
+
])
|
| 79 |
+
|
| 80 |
+
# Predict
|
| 81 |
+
img = Image.open("your_image.jpg").convert("RGB")
|
| 82 |
+
with torch.no_grad():
|
| 83 |
+
probs = torch.softmax(model(tf(img).unsqueeze(0)), dim=1)[0]
|
| 84 |
+
|
| 85 |
+
labels = ["Abaya", "Thobe"]
|
| 86 |
+
print(f"{labels[probs.argmax()]}: {probs.max():.1%} confidence")
|
| 87 |
+
```
|