ResNet Variants Parameters ---------- block : Block Class for the residual block. Options are BasicBlockV1, BottleneckV1. layers : list of int Numbers of layers in each block classes : int, default 1000 Number of classification classes. dilated : bool,
| 196 | |
| 197 | |
| 198 | class ResNet(nn.Module): |
| 199 | """ResNet Variants |
| 200 | Parameters |
| 201 | ---------- |
| 202 | block : Block |
| 203 | Class for the residual block. Options are BasicBlockV1, BottleneckV1. |
| 204 | layers : list of int |
| 205 | Numbers of layers in each block |
| 206 | classes : int, default 1000 |
| 207 | Number of classification classes. |
| 208 | dilated : bool, default False |
| 209 | Applying dilation strategy to pretrained ResNet yielding a stride-8 model, |
| 210 | typically used in Semantic Segmentation. |
| 211 | norm_layer : object |
| 212 | Normalization layer used in backbone network (default: :class:`mxnet.gluon.nn.BatchNorm`; |
| 213 | for Synchronized Cross-GPU BachNormalization). |
| 214 | Reference: |
| 215 | - He, Kaiming, et al. "Deep residual learning for image recognition." Proceedings of the IEEE conference on computer vision and pattern recognition. 2016. |
| 216 | - Yu, Fisher, and Vladlen Koltun. "Multi-scale context aggregation by dilated convolutions." |
| 217 | """ |
| 218 | # pylint: disable=unused-variable |
| 219 | def __init__(self, block, layers, radix=1, groups=1, bottleneck_width=64, |
| 220 | num_classes=1000, dilated=False, dilation=1, |
| 221 | deep_stem=False, stem_width=64, avg_down=False, |
| 222 | rectified_conv=False, rectify_avg=False, |
| 223 | avd=False, avd_first=False, |
| 224 | final_drop=0.0, dropblock_prob=0, |
| 225 | last_gamma=False, norm_layer=nn.BatchNorm2d, |
| 226 | width=1, in_channel=3): |
| 227 | self.cardinality = groups |
| 228 | self.bottleneck_width = bottleneck_width |
| 229 | # ResNet-D params |
| 230 | self.inplanes = stem_width*2 if deep_stem else max(int(64 * width), 64) |
| 231 | self.base = int(64 * width) |
| 232 | self.avg_down = avg_down |
| 233 | self.last_gamma = last_gamma |
| 234 | # ResNeSt params |
| 235 | self.radix = radix |
| 236 | self.avd = avd |
| 237 | self.avd_first = avd_first |
| 238 | |
| 239 | super(ResNet, self).__init__() |
| 240 | self.rectified_conv = rectified_conv |
| 241 | self.rectify_avg = rectify_avg |
| 242 | if rectified_conv: |
| 243 | from rfconv import RFConv2d |
| 244 | conv_layer = RFConv2d |
| 245 | else: |
| 246 | conv_layer = nn.Conv2d |
| 247 | conv_kwargs = {'average_mode': rectify_avg} if rectified_conv else {} |
| 248 | if deep_stem: |
| 249 | self.conv1 = nn.Sequential( |
| 250 | conv_layer(in_channel, stem_width, kernel_size=3, stride=2, padding=1, bias=False, **conv_kwargs), |
| 251 | norm_layer(stem_width), |
| 252 | nn.ReLU(inplace=True), |
| 253 | conv_layer(stem_width, stem_width, kernel_size=3, stride=1, padding=1, bias=False, **conv_kwargs), |
| 254 | norm_layer(stem_width), |
| 255 | nn.ReLU(inplace=True), |
no outgoing calls
no test coverage detected