MCPcopy Create free account
hub / github.com/Sirwenhao/Deep-Learning-Notes / __init__

Method __init__

CV/Pytorch_classification/AlexNet/model.py:6–34  ·  view source on GitHub ↗
(self, num_classes = 1000, init_weights = False)

Source from the content-addressed store, hash-verified

4
5class AlexNet(nn.Module):
6 def __init__(self, num_classes = 1000, init_weights = False):
7 super(AlexNet, self).__init__()
8 self.features = nn.Sequential(
9 nn.Conv2d(3, 48, kernel_size = 11, stride = 4, padding = 2), #padding也可以是tuple:(1,2),
10 # 1表示上下方各补一行0,2代表左右两侧各补2列0
11 nn.ReLU(inplace = True),
12 nn.MaxPool2d(kernel_size = 3, stride = 2),
13 nn.Conv2d(48, 128, kernel_size = 5, padding = 2),
14 nn.ReLU(inplace = True),
15 nn.MaxPool2d(kernel_size = 3, stride = 2),
16 nn.Conv2d(128, 192, kernel_size = 3, padding = 1),
17 nn.ReLU(inplace = True),
18 nn.Conv2d(192, 192, kernel_size = 3, padding = 1),
19 nn.ReLU(inplace = True),
20 nn.Conv2d(192, 128, kernel_size = 3, padding = 1),
21 nn.ReLU(inplace = True),
22 nn.MaxPool2d(kernel_size = 3, stride = 2),
23 )
24 self.classifier = nn.Sequential(
25 nn.Dropout(p = 0.5),
26 nn.Linear(128 * 6 * 6, 2048),
27 nn.ReLU(inplace = True),
28 nn.Dropout(p = 0.5),
29 nn.Linear(2048, 2048),
30 nn.ReLU(inplace = True),
31 nn.Linear(2048, num_classes),
32 )
33 if init_weights:
34 self._initialize_weights()
35
36 def forward(self, x):
37 x = self.features(x)

Callers

nothing calls this directly

Calls 1

_initialize_weightsMethod · 0.95

Tested by

no test coverage detected