forked from prathibha13/Real-time-detection-of-ASL-Alphabets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresnet_models.py
More file actions
28 lines (22 loc) · 937 Bytes
/
resnet_models.py
File metadata and controls
28 lines (22 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python
# coding: utf-8
import torch.nn as nn
import joblib
import torchvision.models as models
from torchvision.models import ResNet18_Weights
# load the binarized labels
print('Loading label binarizer...')
lb = joblib.load('ASL\\output\\lb.pkl')
class ResnetModel(nn.Module):
def __init__(self):
super(ResnetModel, self).__init__()
# Load a pretrained ResNet18 using the new weights API
self.base_model = models.resnet18(weights=ResNet18_Weights.DEFAULT)
# Optionally freeze the feature extractor:
for param in self.base_model.parameters():
param.requires_grad = False
# Replace the final fully connected layer to match the number of classes
num_features = self.base_model.fc.in_features
self.base_model.fc = nn.Linear(num_features, len(lb.classes_))
def forward(self, x):
return self.base_model(x)