-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
31 lines (24 loc) · 843 Bytes
/
Copy pathmodel.py
File metadata and controls
31 lines (24 loc) · 843 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
29
30
31
import torch
import torchvision
from torch import nn
def create_model(num_classes:int=100,
seed:int=42):
Weights=torchvision.models.ResNet50_Weights.DEFAULT
transforms=Weights.transforms()
model=torchvision.models.resnet50(weights=Weights)
for param in model.parameters():
param.require_grad=False
torch.manual_seed(42)
model.fc=nn.Sequential(
torch.nn.Linear(in_features=2048,
out_features=1000),
torch.nn.Dropout(p=0.2,inplace=True),
torch.nn.ReLU(),
torch.nn.Linear(in_features=1000,
out_features=500),
torch.nn.Dropout(),
nn.ReLU(),
torch.nn.Linear(in_features=500,
out_features=num_classes, # same number of output units as our number of classes
bias=True))
return model,transforms