Spaces:
Sleeping
Sleeping
Abdiaziz commited on
Commit ·
bdb546a
1
Parent(s): 56d9391
fixed model architecture error
Browse files
model.py
CHANGED
|
@@ -1,26 +1,25 @@
|
|
|
|
|
| 1 |
import torch
|
| 2 |
import torchvision
|
| 3 |
-
from torchvision import models
|
| 4 |
-
from torch import nn
|
| 5 |
|
| 6 |
-
|
|
|
|
| 7 |
|
| 8 |
-
def
|
| 9 |
# get the weights
|
| 10 |
-
|
| 11 |
# get the transforms
|
| 12 |
-
|
| 13 |
# get the model
|
| 14 |
-
|
| 15 |
|
| 16 |
# freeze all base layers
|
| 17 |
-
for
|
| 18 |
-
|
| 19 |
|
| 20 |
-
#
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
)
|
| 25 |
|
| 26 |
-
return
|
|
|
|
| 1 |
+
# create a fucntions that creates an effnet_b2 model and returns its transformation
|
| 2 |
import torch
|
| 3 |
import torchvision
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
from torch import nn
|
| 6 |
+
from torchvision import models
|
| 7 |
|
| 8 |
+
def create_effnet_b2():
|
| 9 |
# get the weights
|
| 10 |
+
effnet_b2_weights = models.EfficientNet_B2_Weights.DEFAULT
|
| 11 |
# get the transforms
|
| 12 |
+
effnet_b2_transforms = effnet_b2_weights.transforms()
|
| 13 |
# get the model
|
| 14 |
+
effnet_b2 = models.efficientnet_b2(weights = effnet_b2_weights)
|
| 15 |
|
| 16 |
# freeze all base layers
|
| 17 |
+
for params in effnet_b2.parameters():
|
| 18 |
+
params.requires_grad = False
|
| 19 |
|
| 20 |
+
# reset the classifier head
|
| 21 |
+
effnet_b2.classifier = nn.Sequential(nn.Dropout(p = 0.3, inplace = True),
|
| 22 |
+
nn.Linear(in_features = 1408, out_features = 3)
|
| 23 |
+
)
|
|
|
|
| 24 |
|
| 25 |
+
return effnet_b2, effnet_b2_transforms
|