| 147 | return out |
| 148 | |
| 149 | class ResNet_basic(nn.Module): |
| 150 | def __init__(self, block, num_blocks, num_classes=10, cfg=None): |
| 151 | super(ResNet_basic, self).__init__() |
| 152 | self.train_sup = (num_classes > 0) |
| 153 | |
| 154 | self.in_planes = 16 |
| 155 | self.conv1 = nn.Conv2d(3, 16, kernel_size=3, stride=1, padding=1, bias=False) |
| 156 | self.bn1 = nn.BatchNorm2d(16, affine=True) |
| 157 | self.layer1 = self._make_layer(block, 16, num_blocks[0], stride=1) |
| 158 | self.layer2 = self._make_layer(block, 32, num_blocks[1], stride=2) |
| 159 | self.layer3 = self._make_layer(block, 64, num_blocks[2], stride=2) |
| 160 | self.output_dim = 512*block.expansion |
| 161 | if(self.train_sup): |
| 162 | self.linear = nn.Linear(64*block.expansion, num_classes) |
| 163 | |
| 164 | def _make_layer(self, block, planes, num_blocks, stride): |
| 165 | strides = [stride] + [1]*(num_blocks-1) |
| 166 | layers = [] |
| 167 | for stride in strides: |
| 168 | layers.append(block(self.in_planes, planes, stride)) |
| 169 | self.in_planes = planes * block.expansion |
| 170 | return nn.Sequential(*layers) |
| 171 | |
| 172 | def forward(self, x): |
| 173 | out = F.relu(self.bn1(self.conv1(x))) |
| 174 | out = self.layer1(out) |
| 175 | out = self.layer2(out) |
| 176 | out = self.layer3(out) |
| 177 | out = F.adaptive_avg_pool2d(out, (1, 1)) |
| 178 | out = out.view(out.size(0), -1) |
| 179 | if(self.train_sup): |
| 180 | out = self.linear(out) |
| 181 | return out |
| 182 | |
| 183 | |
| 184 | def get_block(block): |
no outgoing calls
no test coverage detected
searching dependent graphs…