in utils/gluon/utils/resnetv1.py [0:0]
def __init__(self, in_planes, mid_planes, out_planes, groups=1, strides=1,
norm_kwargs=None, last_gamma=False, name_prefix=None,
down_pos=0, use_se=False, se_planes=-1, extra_bn=False,
**kwargs):
super(_BottleneckV1, self).__init__(prefix=name_prefix)
assert down_pos in [0, 1, 2], \
"down_pos value({}) is unknown.".format(down_pos)
strides1 = strides if down_pos == 0 else 1
strides2 = strides if down_pos == 1 else 1
strides3 = strides if down_pos == 2 else 1
with self.name_scope():
if extra_bn:
# note: se-block seems not converage well on ResNet152
self.bn1a = nn.BatchNorm(in_channels=in_planes, prefix='bn1a',
center=False, scale=False,
**({} if norm_kwargs is None else norm_kwargs))
# extract information
self.conv1 = nn.Conv2D(channels=mid_planes, in_channels=in_planes,
kernel_size=1, use_bias=False, strides=strides1,
prefix='conv1')
self.bn1 = nn.BatchNorm(in_channels=mid_planes, prefix='bn1',
**({} if norm_kwargs is None else norm_kwargs))
self.relu1 = nn.Activation('relu')
# capture spatial relations
self.conv2 = nn.Conv2D(channels=mid_planes, in_channels=mid_planes,
kernel_size=3, padding=1, groups=groups,
strides=strides2, use_bias=False, prefix='conv2')
self.bn2 = nn.BatchNorm(in_channels=mid_planes, prefix='bn2',
**({} if norm_kwargs is None else norm_kwargs))
self.relu2 = nn.Activation('relu')
# embeding back to information highway
self.conv3 = nn.Conv2D(channels=out_planes, in_channels=mid_planes,
kernel_size=1, use_bias=False, strides=strides3,
prefix='conv3')
self.bn3 = nn.BatchNorm(in_channels=out_planes, prefix='bn3',
gamma_initializer='zeros' if last_gamma else 'ones',
**({} if norm_kwargs is None else norm_kwargs))
self.se_block = nn.SE(in_channels=out_planes, channels=se_planes,
prefix='se') if use_se else None
# this relue is added after fusion
self.relu3 = nn.Activation('relu')
if strides != 1 or in_planes != out_planes:
if extra_bn:
# note: se-block seems not converage well on ResNet152
self.bn4a = nn.BatchNorm(in_channels=in_planes, prefix='bn4a',
center=False, scale=False,
**({} if norm_kwargs is None else norm_kwargs))
self.conv4 = nn.Conv2D(channels=out_planes, in_channels=in_planes,
kernel_size=1, strides=strides, use_bias=False,
prefix='conv4')
self.bn4 = nn.BatchNorm(in_channels=out_planes, prefix='bn4',
**({} if norm_kwargs is None else norm_kwargs))