-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBuild_Network.py
More file actions
31 lines (24 loc) · 924 Bytes
/
Build_Network.py
File metadata and controls
31 lines (24 loc) · 924 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
from collections import OrderedDict
from torch import nn
import torchvision.models as models
def build_network(model, hidden, output):
Input = 25088
arcch = 'vgg16'
if model == 'densenet121':
Input = 1024
model = models.densenet121(pretrained=True)
arcch = 'densenet121'
elif model == 'vgg16':
model = models.vgg16(pretrained=True)
else:
print("Sorry! Not found\n defualt vgg16")
model = models.vgg16(pretrained=True)
for param in model.parameters():
param.requires_grad = False
classifier = nn.Sequential(nn.Linear(Input, hidden),
nn.ReLU(),
nn.Dropout(0.2),
nn.Linear(hidden, output),
nn.LogSoftmax(dim=1))
model.classifier = classifier
return model, arcch