Views
No views yet
layer1-layer3, fine-tuned layer4 + custom head:
Linear(512, 256) -> BatchNorm1d(256) -> ReLU -> Dropout(0.3) -> Linear(256, 24)1import torch
2import torchvision.models as models
3import torch.nn as nn
4from PIL import Image
5from torchvision import transforms
6from huggingface_hub import hf_hub_download
7
8# 1. Define Model Architecture
9model = models.resnet18()
10model.fc = nn.Sequential(
11 nn.Linear(512, 256),
12 nn.BatchNorm1d(256),
13 nn.ReLU(),
14 nn.Dropout(0.3),
15 nn.Linear(256, 24)
16)
17
18# 2. Download and Load Model Weights
19weights_path = hf_hub_download(repo_id="Vecrist/resnet18-handsign-classifier", filename="ResNet-18_9848AccModel_weights.pth")
20model.load_state_dict(torch.load(weights_path, map_location="cpu"))
21model.eval()
22
23# 3. Preprocess Image
24transform = transforms.Compose([
25 transforms.Resize((224, 224)),
26 transforms.ToTensor(),
27 transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
28])
29
30# 4. Predict
31# img = Image.open("path_to_handsign_image.jpg").convert("RGB")
32# outputs = model(transform(img).unsqueeze(0))
33# predicted_class_idx = outputs.argmax(dim=1).item()0.0001 for layer4, 0.001 for FC head).CrossEntropyLossRandomResizedCrop(224), RandomHorizontalFlip, ImageNet Normalization.