Spaces:
Build error
Build error
Update model.py
Browse files
model.py
CHANGED
@@ -3,22 +3,20 @@ import torchvision
|
|
3 |
|
4 |
from torch import nn
|
5 |
|
6 |
-
def
|
7 |
-
|
8 |
-
#
|
9 |
weights = torchvision.models.ViT_B_16_Weights.DEFAULT
|
10 |
transforms = weights.transforms()
|
11 |
model = torchvision.models.vit_b_16(weights=weights)
|
12 |
|
13 |
-
#
|
14 |
for param in model.parameters():
|
15 |
param.requires_grad = False
|
16 |
|
17 |
-
#
|
18 |
torch.manual_seed(seed)
|
19 |
-
model.
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
return model, transforms
|
|
|
3 |
|
4 |
from torch import nn
|
5 |
|
6 |
+
def create_vit_model(num_classes:int=325,
|
7 |
+
seed:int=42):
|
8 |
+
# Create ViT_B_16 pretrained weights, transforms and model
|
9 |
weights = torchvision.models.ViT_B_16_Weights.DEFAULT
|
10 |
transforms = weights.transforms()
|
11 |
model = torchvision.models.vit_b_16(weights=weights)
|
12 |
|
13 |
+
# Freeze all of the base layers
|
14 |
for param in model.parameters():
|
15 |
param.requires_grad = False
|
16 |
|
17 |
+
# Change classifier head to suit our needs
|
18 |
torch.manual_seed(seed)
|
19 |
+
model.heads = nn.Sequential(nn.Linear(in_features=768,
|
20 |
+
out_features=325))
|
21 |
+
|
22 |
+
return model, transforms
|
|
|
|