-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
28 lines (22 loc) · 912 Bytes
/
model.py
File metadata and controls
28 lines (22 loc) · 912 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
# file that builds the classification model
#imports
from torchvision import datasets, transforms, models
from torch import nn
import torch
def getModel(path="./saved_models/pedestrianClassifier5Epochsiou045-2020-10-20-11-15-47.pt"):
'''
getModel creates pytorch model and sets trained weights
params:
path: path to the saved weights
return:
pytorch model for pedestrian classification
'''
# get model from library
model = models.resnet50(pretrained=True)
# remove original output layer and replace it with 2 dimensinal layer
number_input_features = model.fc.in_features
num_classes =2
model.fc = nn.Linear(number_input_features, num_classes)
# load model trained in second notebook
model.load_state_dict(torch.load('./saved_models/pedestrianClassifier12Epochs-iou45-2020-10-21-13-45-26.pt'))
return model