(input_x, base_channel, scope, stride=1, projection=False, avg_down=True)
for bottleneck_v1b: reduce spatial dim in conv_3x3 with stride 2.
for bottleneck_v1b: reduce spatial dim in conv_3x3 with stride 2.
for bottleneck_v1b : reduce spatial dim in conv_3x3 with stride 2 .
def bottleneck_v1b(input_x, base_channel, scope, stride=1, projection=False, avg_down=True):
    '''
    for bottleneck_v1b: reduce spatial dim in conv_3x3 with stride 2.
    '''
    with tf.variable_scope(scope):
        if DEBUG:
            debug_dict[input_x.op.name] = tf.transpose(input_x, [0, 3, 1, 2])
        net = slim.conv2d(input_x, num_outputs=base_channel, kernel_size=[1, 1], stride=1,
                          padding="VALID", biases_initializer=None, data_format=DATA_FORMAT,
                          scope='conv0')
        if DEBUG:
            debug_dict[net.op.name] = tf.transpose(net, [0, 3, 1, 2])

        net = tf.pad(net, paddings=[[0, 0], [1, 1], [1, 1], [0, 0]])
        if DEBUG:
            debug_dict[net.op.name] = tf.transpose(net, [0, 3, 1, 2])

        net = slim.conv2d(net, num_outputs=base_channel, kernel_size=[3, 3], stride=stride,
                          padding="VALID", biases_initializer=None, data_format=DATA_FORMAT,
                          scope='conv1')
        if DEBUG:
            debug_dict[net.op.name] = tf.transpose(net, [0, 3, 1, 2])
        net = slim.conv2d(net, num_outputs=base_channel * 4, kernel_size=[1, 1], stride=1,
                          padding="VALID", biases_initializer=None, data_format=DATA_FORMAT,
                          activation_fn=None, scope='conv2')
        if DEBUG:
            debug_dict[net.op.name] = tf.transpose(net, [0, 3, 1, 2])
        # Note that : gamma in the last conv should be init with 0.
        # But we just reload params from mxnet, so don't specific batch norm initializer
        if projection:

            if avg_down:  # design for resnet_v1d
                '''
                In GluonCV, padding is "ceil mode". Here we use "SAME" to replace it, which may cause Erros.
                And the erro will grow with depth of resnet. e.g. res101 erro > res50 erro
                '''
                shortcut = slim.avg_pool2d(input_x, kernel_size=[stride, stride], stride=stride, padding="SAME",
                                           data_format=DATA_FORMAT)
                if DEBUG:
                    debug_dict[shortcut.op.name] = tf.transpose(shortcut, [0, 3, 1, 2])

                shortcut = slim.conv2d(shortcut, num_outputs=base_channel*4, kernel_size=[1, 1],
                                       stride=1, padding="VALID", biases_initializer=None, data_format=DATA_FORMAT,
                                       activation_fn=None,
                                       scope='shortcut')
                if DEBUG:
                    debug_dict[shortcut.op.name] = tf.transpose(shortcut, [0, 3, 1, 2])
                # shortcut should have batch norm.
            else:
                shortcut = slim.conv2d(input_x, num_outputs=base_channel * 4, kernel_size=[1, 1],
                                       stride=stride, padding="VALID", biases_initializer=None, activation_fn=None,
                                       data_format=DATA_FORMAT,
                                       scope='shortcut')
                if DEBUG:
                    debug_dict[shortcut.op.name] = tf.transpose(shortcut, [0, 3, 1, 2])
        else:
            shortcut = tf.identity(input_x, name='shortcut/Identity')
            if DEBUG:
                debug_dict[shortcut.op.name] = tf.transpose(shortcut, [0, 3, 1, 2])

        net = net + shortcut
        if DEBUG:
            debug_dict[net.op.name] = tf.transpose(net, [0, 3, 1, 2])
        net = tf.nn.relu(net)
        if DEBUG:
            debug_dict[net.op.name] = tf.transpose(net, [0, 3, 1, 2])
        return net
def bottleneck_v1b ( input_x , base_channel , scope , stride = 1 , projection = False , avg_down = True ) : with tf . variable_scope ( scope ) : if DEBUG : debug_dict [ input_x . op . name ] = tf . transpose ( input_x , [ 0 , 3 , 1 , 2 ] ) net = slim . conv2d ( input_x , num_outputs = base_channel , kernel_size = [ 1 , 1 ] , stride = 1 , padding = "VALID" , biases_initializer = None , data_format = DATA_FORMAT , scope = 'conv0' ) if DEBUG : debug_dict [ net . op . name ] = tf . transpose ( net , [ 0 , 3 , 1 , 2 ] ) net = tf . pad ( net , paddings = [ [ 0 , 0 ] , [ 1 , 1 ] , [ 1 , 1 ] , [ 0 , 0 ] ] ) if DEBUG : debug_dict [ net . op . name ] = tf . transpose ( net , [ 0 , 3 , 1 , 2 ] ) net = slim . conv2d ( net , num_outputs = base_channel , kernel_size = [ 3 , 3 ] , stride = stride , padding = "VALID" , biases_initializer = None , data_format = DATA_FORMAT , scope = 'conv1' ) if DEBUG : debug_dict [ net . op . name ] = tf . transpose ( net , [ 0 , 3 , 1 , 2 ] ) net = slim . conv2d ( net , num_outputs = base_channel * 4 , kernel_size = [ 1 , 1 ] , stride = 1 , padding = "VALID" , biases_initializer = None , data_format = DATA_FORMAT , activation_fn = None , scope = 'conv2' ) if DEBUG : debug_dict [ net . op . name ] = tf . transpose ( net , [ 0 , 3 , 1 , 2 ] ) # Note that : gamma in the last conv should be init with 0. # But we just reload params from mxnet, so don't specific batch norm initializer if projection : if avg_down : # design for resnet_v1d '''
                In GluonCV, padding is "ceil mode". Here we use "SAME" to replace it, which may cause Erros.
                And the erro will grow with depth of resnet. e.g. res101 erro > res50 erro
                ''' shortcut = slim . avg_pool2d ( input_x , kernel_size = [ stride , stride ] , stride = stride , padding = "SAME" , data_format = DATA_FORMAT ) if DEBUG : debug_dict [ shortcut . op . name ] = tf . transpose ( shortcut , [ 0 , 3 , 1 , 2 ] ) shortcut = slim . conv2d ( shortcut , num_outputs = base_channel * 4 , kernel_size = [ 1 , 1 ] , stride = 1 , padding = "VALID" , biases_initializer = None , data_format = DATA_FORMAT , activation_fn = None , scope = 'shortcut' ) if DEBUG : debug_dict [ shortcut . op . name ] = tf . transpose ( shortcut , [ 0 , 3 , 1 , 2 ] ) # shortcut should have batch norm. else : shortcut = slim . conv2d ( input_x , num_outputs = base_channel * 4 , kernel_size = [ 1 , 1 ] , stride = stride , padding = "VALID" , biases_initializer = None , activation_fn = None , data_format = DATA_FORMAT , scope = 'shortcut' ) if DEBUG : debug_dict [ shortcut . op . name ] = tf . transpose ( shortcut , [ 0 , 3 , 1 , 2 ] ) else : shortcut = tf . identity ( input_x , name = 'shortcut/Identity' ) if DEBUG : debug_dict [ shortcut . op . name ] = tf . transpose ( shortcut , [ 0 , 3 , 1 , 2 ] ) net = net + shortcut if DEBUG : debug_dict [ net . op . name ] = tf . transpose ( net , [ 0 , 3 , 1 , 2 ] ) net = tf . nn . relu ( net ) if DEBUG : debug_dict [ net . op . name ] = tf . transpose ( net , [ 0 , 3 , 1 , 2 ] ) return net