-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmodel.py
45 lines (33 loc) · 1.15 KB
/
model.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
#
# boostcamp AI Tech
# Mask Image Classification Competition
#
import torch
import torch.nn as nn
import torchvision.models as models
class EfficientNet_b3(nn.Module):
def __init__(self) -> None:
super().__init__()
self.fc = nn.Linear(1536, 18, bias=True)
torch.nn.init.kaiming_normal_(self.fc.weight)
torch.nn.init.zeros_(self.fc.bias)
self.effnetb3 = models.efficientnet_b3(pretrained=True)
self.effnetb3.classifier = nn.Sequential(
nn.Dropout(p=0.3, inplace=True),
self.fc
)
def forward(self, x: torch.Tensor) -> torch.Tensor:
return self.effnetb3(x)
class EfficientNet_b4(nn.Module):
def __init__(self) -> None:
super().__init__()
self.fc = nn.Linear(1792, 18, bias=True)
torch.nn.init.kaiming_normal_(self.fc.weight)
torch.nn.init.zeros_(self.fc.bias)
self.effnetb4 = models.efficientnet_b4(pretrained=True)
self.effnetb4.classifier = nn.Sequential(
nn.Dropout(p=0.4, inplace=True),
self.fc
)
def forward(self, x: torch.Tensor) -> torch.Tensor:
return self.effnetb4(x)