-
Notifications
You must be signed in to change notification settings - Fork 5
/
model_mask.py
61 lines (46 loc) · 1.7 KB
/
model_mask.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import torch.nn as nn
import torch.nn.functional as F
import torchvision.models as models
import timm
# Custom Model Template
class ModelMask(nn.Module):
def __init__(self, num_classes):
super().__init__()
self.backbone = models.efficientnet_b0(pretrained=True)
self.backbone.classifier[1] = nn.Linear(self.backbone.classifier[1].in_features, num_classes)
def forward(self, x):
return self.backbone(x)
class Resnet50(nn.Module):
def __init__(self, num_classes):
super().__init__()
self.backbone = models.resnet50(pretrained=True)
n_input = self.backbone.fc.in_features
last = nn.Linear(n_input, num_classes)
self.backbone.fc = last
def forward(self, x):
x = self.backbone(x)
return x
class Resnet152(nn.Module):
def __init__(self, num_classes):
super().__init__()
self.backbone = models.resnet152(pretrained=True)
self.backbone.fc = nn.Linear(self.backbone.fc.in_features, num_classes)
def forward(self, x):
return self.backbone(x)
class VGG19(nn.Module):
def __init__(self, num_classes):
super().__init__()
self.backbone = models.vgg19(pretrained=True)
self.backbone.classifier[6] = nn.Linear(self.backbone.classifier[6].in_features, num_classes)
def forward(self, x):
return self.backbone(x)
class GoogLeNet(nn.Module):
def __init__(self, num_classes):
super().__init__()
self.backbone = models.googlenet(pretrained=True)
n_input = self.backbone.fc.in_features
last = nn.Linear(n_input, num_classes)
self.backbone.fc = last
def forward(self, x):
x = self.backbone(x)
return x