noelsinghsr commited on
Commit
a6530f2
1 Parent(s): 76dfc1a

Upload model.py

Browse files
Files changed (1) hide show
  1. model.py +24 -0
model.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import torch
3
+ import torchvision
4
+
5
+ from torch import nn
6
+
7
+ def create_effnetb2_model(num_classes:int=101):
8
+
9
+ # 1, 2, 3 Create EffNetB2 pretrained weights, transforms and model
10
+ weights = torchvision.models.EfficientNet_B2_Weights.DEFAULT
11
+ transforms = weights.transforms()
12
+ model = torchvision.models.efficientnet_b2(weights=weights)
13
+
14
+ # 4. Freeze all layers in the base model
15
+ for param in model.parameters():
16
+ param.requires_grad = False
17
+
18
+ # 5. Change classifier head with random seed for reproducibility
19
+ model.classifier = nn.Sequential(
20
+ nn.Dropout(p=0.3, inplace=True),
21
+ nn.Linear(in_features=1408, out_features=num_classes)
22
+ )
23
+
24
+ return model, transforms