forked from geekcomputers/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathefficientnet.py
More file actions
43 lines (38 loc) · 1.39 KB
/
Copy pathefficientnet.py
File metadata and controls
43 lines (38 loc) · 1.39 KB
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
import torch.nn as nn
from ..nn.convolution import EfficientNetBlock
class EfficientNetB0(nn.Module):
def __init__(self, num_classes=1000):
super().__init__()
self.stem = nn.Sequential(
nn.Conv2d(3, 32, 3, stride=2, padding=1, bias=False),
nn.BatchNorm2d(32),
nn.SiLU(inplace=True)
)
self.blocks = nn.Sequential(
EfficientNetBlock(32, 16, 3, 1, 1),
EfficientNetBlock(16, 24, 3, 2, 6),
EfficientNetBlock(24, 24, 3, 1, 6),
EfficientNetBlock(24, 40, 5, 2, 6),
EfficientNetBlock(40, 40, 5, 1, 6),
EfficientNetBlock(40, 80, 3, 2, 6),
EfficientNetBlock(80, 80, 3, 1, 6),
EfficientNetBlock(80, 112, 5, 1, 6),
EfficientNetBlock(112, 112, 5, 1, 6),
EfficientNetBlock(112, 192, 5, 2, 6),
EfficientNetBlock(192, 192, 5, 1, 6),
EfficientNetBlock(192, 320, 3, 1, 6),
)
self.head = nn.Sequential(
nn.Conv2d(320, 1280, 1, bias=False),
nn.BatchNorm2d(1280),
nn.SiLU(inplace=True),
nn.AdaptiveAvgPool2d(1),
nn.Flatten(),
nn.Dropout(0.2),
nn.Linear(1280, num_classes)
)
def forward(self, x):
x = self.stem(x)
x = self.blocks(x)
x = self.head(x)
return x