Spaces:
Sleeping
Sleeping
ranggaaldosas
commited on
Commit
•
4ea7f67
1
Parent(s):
f1c7739
Upload requirements.txt
Browse files- requirements.txt +33 -0
requirements.txt
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import torchvision
|
3 |
+
|
4 |
+
from torch import nn
|
5 |
+
|
6 |
+
|
7 |
+
def create_effnetb2_model(num_classes: int = 101, seed: int = 42):
|
8 |
+
"""Creates an EfficientNetB2 feature extractor model and transforms.
|
9 |
+
Args:
|
10 |
+
num_classes (int, optional): number of classes in the classifier head.
|
11 |
+
Defaults to 3.
|
12 |
+
seed (int, optional): random seed value. Defaults to 42.
|
13 |
+
Returns:
|
14 |
+
model (torch.nn.Module): EffNetB2 feature extractor model.
|
15 |
+
transforms (torchvision.transforms): EffNetB2 image transforms.
|
16 |
+
"""
|
17 |
+
# Create EffNetB2 pretrained weights, transforms and model
|
18 |
+
weights = torchvision.models.EfficientNet_B2_Weights.DEFAULT
|
19 |
+
transforms = weights.transforms()
|
20 |
+
model = torchvision.models.efficientnet_b2(weights=weights)
|
21 |
+
|
22 |
+
# Freeze all layers in base model
|
23 |
+
for param in model.parameters():
|
24 |
+
param.requires_grad = False
|
25 |
+
|
26 |
+
# Change classifier head with random seed for reproducibility
|
27 |
+
torch.manual_seed(seed)
|
28 |
+
model.classifier = nn.Sequential(
|
29 |
+
nn.Dropout(p=0.3, inplace=True),
|
30 |
+
nn.Linear(in_features=1408, out_features=num_classes),
|
31 |
+
)
|
32 |
+
|
33 |
+
return model, transforms
|