文章目录
代码来自MXNET
ResNet
ResNet-18
和ResNet-34
使用的是Basic Block
,而ResNet-50以及更深层的网络使用的是Bottleneck block
class BasicBlockV1b(HybridBlock):
"""ResNetV1b BasicBlockV1b
"""
expansion = 1
def __init__(self, planes, strides=1, dilation=1, downsample=None,
previous_dilation=1, norm_layer=None, norm_kwargs=None, **kwargs):
super(BasicBlockV1b, self).__init__()
norm_kwargs = norm_kwargs if norm_kwargs is not None else {
}
# first 3x3 conv
self.conv1 = nn.Conv2D(channels=planes, kernel_size=3, strides=strides,
padding=dilation, dilation=dilation, use_bias=False)
self.bn1 = norm_layer(in_channels=planes, **({
} if norm_kwargs is None else norm_kwargs))
self.relu1 = nn.Activation('relu')
# second 3x3 conv
self.conv2 = nn.Conv2D(channels=planes, kernel_size=3, strides=1,
padding=previous_dilation, dilation=previous_dilation,
use_bias=False)
self.bn2 = norm_layer(in_channels=planes, **({
} if<