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

Method __init__

CV/Pytorch_classification/ResNet/model.py:86–115  ·  view source on GitHub ↗
(self, 
                block,
                blocks_num,
                num_classes=1000,
                include_top=True,
                groups=1,
                width_per_group=64)

Source from the content-addressed store, hash-verified

84
85class ResNet(nn.Module):
86 def __init__(self,
87 block,
88 blocks_num,
89 num_classes=1000,
90 include_top=True,
91 groups=1,
92 width_per_group=64):
93 super(ResNet, self).__init__()
94 self.include_top = include_top
95 self.in_channel = 64
96
97 self.groups = groups
98 self.width_per_group = width_per_group
99
100 self.conv1 = nn.Conv2d(3, self.in_channel, kernel_size=7, stride=2,
101 padding=3, bias=False)
102 self.bn1 = nn.BatchNorm2d(self.in_channel)
103 self.relu = nn.ReLU(inplace=True)
104 self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1)
105 self.layer1 = self._make_layer(block, 64, blocks_num[0])
106 self.layer2 = self._make_layer(block, 128, blocks_num[1], stride=2)
107 self.layer3 = self._make_layer(block, 256, blocks_num[2], stride=2)
108 self.layer4 = self._make_layer(block, 512, blocks_num[3], stride=2)
109 if self.include_top:
110 self.avgpool = nn.AdaptiveAvgPool2d((1, 1))
111 self.fc = nn.Linear(512 * block.expansion, num_classes)
112
113 for m in self.modules():
114 if isinstance(m, nn.Conv2d):
115 nn.init.kaiming_normal_(m.weight, mode='fan_out', nonlinearity='relu') # pytorch新版本已经更新nn.init.kaiming_nomal为nn.kaiming_normal_
116
117 def _make_layer(self, block, channel, block_num, stride=1):
118 downsample = None

Callers 2

__init__Method · 0.45
__init__Method · 0.45

Calls 1

_make_layerMethod · 0.95

Tested by

no test coverage detected