rdkulkarni commited on
Commit
f8f26d2
1 Parent(s): 923c92d

Upload model.py

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