def __init__(self, in_planes, planes, stride=1): super(BasicBlock, self).__init__() self.conv1 = conv3x3(in_planes, planes, stride) self.bn1 = nn.BatchNorm2d(planes) self.conv2 = conv3x3(planes, planes) self.bn2 = nn.BatchNorm2d(planes) self.shortcut = nn.Sequential() if stride != 1 or in_planes != self.expansion * planes: self.shortcut = nn.Sequential( nn.Conv2d(in_planes, self.expansion * planes, kernel_size=1, stride=stride), nn.BatchNorm2d(self.expansion * planes) )
def __init__(self, num_classes): super(ResNet18, self).__init__() self.in_planes = 16 self.conv1 = conv3x3(1, 16) self.bn1 = nn.BatchNorm2d(16) self.layer1 = self._make_layer(BasicBlock, 16, 2, stride=1) self.layer2 = self._make_layer(BasicBlock, 32, 2, stride=2) self.layer3 = self._make_layer(BasicBlock, 64, 2, stride=2) self.linear = nn.Linear(64 * BasicBlock.expansion, num_classes)