The backbone (MobileNetV2) was frozen. Only the custom classifier head was trained:
1import torch
2import torch.nn as nn
3import torchvision.models as models
4import torchvision.transforms as transforms
5from huggingface_hub import hf_hub_download
6from PIL import Image
7
8# Load model
9weights = hf_hub_download("Resham2987/abaya-and-thobes-classifier", "pytorch_model.bin")
10
11model = models.mobilenet_v2(weights=None)
12model.classifier = nn.Sequential(
13 nn.Dropout(0.3), nn.Linear(1280, 128),
14 nn.ReLU(), nn.Dropout(0.2), nn.Linear(128, 2)
15)
16model.load_state_dict(torch.load(weights, map_location="cpu"))
17model.eval()
18
19# Preprocess
20tf = transforms.Compose([
21 transforms.Resize((224, 224)),
22 transforms.ToTensor(),
23 transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),
24])
25
26# Predict
27img = Image.open("your_image.jpg").convert("RGB")
28with torch.no_grad():
29 probs = torch.softmax(model(tf(img).unsqueeze(0)), dim=1)[0]
30
31labels = ["Abaya", "Thobe"]
32print(f"{labels[probs.argmax()]}: {probs.max():.1%} confidence")