(block_fn, layers, data_format=None)
return model
Generator for X-Det ResNet v2 models.

  Args:
    block_fn: The block to use within the model, either `building_block` or
      `bottleneck_block`.
    layers: A length-4 array denoting the number of blocks to include in each
      layer. Each layer consists of blocks that take inputs of the same size.
    data_format: The input format ('channels_last', 'channels_first', or None).
      If set to None, the format is dependent on whether a GPU is available.

  Returns:
    The model function that takes in `inputs` and `is_training` and
    returns the output tensor of the ResNet model.
Generator for X-Det ResNet v2 models.
Generator for X - Det ResNet v2 models .
def xdet_resnet_v4_generator(block_fn, layers, data_format=None):
  """Generator for X-Det ResNet v2 models.

  Args:
    block_fn: The block to use within the model, either `building_block` or
      `bottleneck_block`.
    layers: A length-4 array denoting the number of blocks to include in each
      layer. Each layer consists of blocks that take inputs of the same size.
    data_format: The input format ('channels_last', 'channels_first', or None).
      If set to None, the format is dependent on whether a GPU is available.

  Returns:
    The model function that takes in `inputs` and `is_training` and
    returns the output tensor of the ResNet model.
  """
  if data_format is None:
    data_format = (
        'channels_first' if tf.test.is_built_with_cuda() else 'channels_last')

  def model(inputs, is_training):
    """Constructs the ResNet model given the inputs."""
    # we do this in preprocess func
    #if data_format == 'channels_first':
      # Convert the inputs from channels_last (NHWC) to channels_first (NCHW).
      # This provides a large performance boost on GPU. See
      # https://www.tensorflow.org/performance/performance_guide#data_formats
      #inputs = tf.transpose(inputs, [0, 3, 1, 2])

    inputs = resnet_v2.conv2d_fixed_padding(
        inputs=inputs, filters=64, kernel_size=7, strides=2,
        data_format=data_format, kernel_initializer=conv_bn_initializer_to_use)
    inputs = tf.identity(inputs, 'initial_conv')
    inputs = tf.layers.max_pooling2d(
        inputs=inputs, pool_size=3, strides=2, padding='SAME',
        data_format=data_format)
    inputs = tf.identity(inputs, 'initial_max_pool')

    inputs = resnet_v2.block_layer(
                            inputs=inputs, filters=64, block_fn=block_fn, blocks=layers[0],
                            strides=1, is_training=is_training, name='block_layer1',
                            data_format=data_format)
    output_conv3 = resnet_v2.block_layer(
                            inputs=inputs, filters=128, block_fn=block_fn, blocks=layers[1],
                            strides=2, is_training=is_training, name='block_layer2',
                            data_format=data_format)
    with tf.variable_scope('attention', values=[inputs, output_conv3]):
      conv3_weights = SEBlock(inputs, 128, data_format, is_training, name='block_layer2')
      output_conv3 = output_conv3 * conv3_weights

    output_conv4 = resnet_v2.block_layer(
                            inputs=output_conv3, filters=256, block_fn=block_fn, blocks=layers[2],
                            strides=2, is_training=is_training, name='block_layer3',
                            data_format=data_format)
    with tf.variable_scope('attention', values=[output_conv3, output_conv4]):
      conv4_weights = SEBlock(output_conv3, 256, data_format, is_training, name='block_layer3')
      output_conv4 = output_conv4 * conv4_weights

    output_conv5 = xdet_block_layer(
                            inputs=output_conv4, filters=512, block_fn=xdet_bottleneck_block, blocks=layers[4],
                            dilation_rate=2, is_training=is_training, name='block_layer4',
                            data_format=data_format)
    with tf.variable_scope('attention', values=[output_conv4, output_conv5]):
      conv5_weights = SEBlock(output_conv4, 512, data_format, is_training, strides=1, name='block_layer4')
      output_conv5 = output_conv5 * conv5_weights

    feat_layers = []
    with tf.variable_scope('channel_split', values=[output_conv5]):
        layer_depth = [512, 1024, 512]
        # kernel_size = [(1,), (3,), (3, 3)]
        # strides = [(1,), (2,), (2, 2)]
        kernel_size = [(3, 1), (3, 1), (3, 3)]
        strides = [(1, 1), (2, 1), (2, 2)]

        multi_res_feature_map = tf.split(output_conv5, layer_depth, axis=(-1 if data_format == 'channels_last' else 1))

        for layer_ind, _depth in enumerate(layer_depth):
            inputs = multi_res_feature_map[layer_ind]
            inputs = resnet_v2.batch_norm_relu(inputs, is_training, data_format)
            for conv_ind, _kernel_size in enumerate(kernel_size[layer_ind]):
                inputs = tf.layers.conv2d(inputs=inputs, filters=_depth,
                                  kernel_size=_kernel_size, strides=strides[layer_ind][conv_ind],
                                  padding='SAME', use_bias=True, activation=tf.nn.relu,
                                  kernel_initializer=initializer_to_use(),
                                  data_format=data_format, name='conv{}_{}'.format(layer_ind + 1, conv_ind + 1))
            feat_layers.append(inputs)

    return feat_layers

  return model
def xdet_resnet_v4_generator ( block_fn , layers , data_format = None ) : if data_format is None : data_format = ( 'channels_first' if tf . test . is_built_with_cuda ( ) else 'channels_last' ) def model ( inputs , is_training ) : """Constructs the ResNet model given the inputs.""" # we do this in preprocess func #if data_format == 'channels_first': # Convert the inputs from channels_last (NHWC) to channels_first (NCHW). # This provides a large performance boost on GPU. See # https://www.tensorflow.org/performance/performance_guide#data_formats #inputs = tf.transpose(inputs, [0, 3, 1, 2]) inputs = resnet_v2 . conv2d_fixed_padding ( inputs = inputs , filters = 64 , kernel_size = 7 , strides = 2 , data_format = data_format , kernel_initializer = conv_bn_initializer_to_use ) inputs = tf . identity ( inputs , 'initial_conv' ) inputs = tf . layers . max_pooling2d ( inputs = inputs , pool_size = 3 , strides = 2 , padding = 'SAME' , data_format = data_format ) inputs = tf . identity ( inputs , 'initial_max_pool' ) inputs = resnet_v2 . block_layer ( inputs = inputs , filters = 64 , block_fn = block_fn , blocks = layers [ 0 ] , strides = 1 , is_training = is_training , name = 'block_layer1' , data_format = data_format ) output_conv3 = resnet_v2 . block_layer ( inputs = inputs , filters = 128 , block_fn = block_fn , blocks = layers [ 1 ] , strides = 2 , is_training = is_training , name = 'block_layer2' , data_format = data_format ) with tf . variable_scope ( 'attention' , values = [ inputs , output_conv3 ] ) : conv3_weights = SEBlock ( inputs , 128 , data_format , is_training , name = 'block_layer2' ) output_conv3 = output_conv3 * conv3_weights output_conv4 = resnet_v2 . block_layer ( inputs = output_conv3 , filters = 256 , block_fn = block_fn , blocks = layers [ 2 ] , strides = 2 , is_training = is_training , name = 'block_layer3' , data_format = data_format ) with tf . variable_scope ( 'attention' , values = [ output_conv3 , output_conv4 ] ) : conv4_weights = SEBlock ( output_conv3 , 256 , data_format , is_training , name = 'block_layer3' ) output_conv4 = output_conv4 * conv4_weights output_conv5 = xdet_block_layer ( inputs = output_conv4 , filters = 512 , block_fn = xdet_bottleneck_block , blocks = layers [ 4 ] , dilation_rate = 2 , is_training = is_training , name = 'block_layer4' , data_format = data_format ) with tf . variable_scope ( 'attention' , values = [ output_conv4 , output_conv5 ] ) : conv5_weights = SEBlock ( output_conv4 , 512 , data_format , is_training , strides = 1 , name = 'block_layer4' ) output_conv5 = output_conv5 * conv5_weights feat_layers = [ ] with tf . variable_scope ( 'channel_split' , values = [ output_conv5 ] ) : layer_depth = [ 512 , 1024 , 512 ] # kernel_size = [(1,), (3,), (3, 3)] # strides = [(1,), (2,), (2, 2)] kernel_size = [ ( 3 , 1 ) , ( 3 , 1 ) , ( 3 , 3 ) ] strides = [ ( 1 , 1 ) , ( 2 , 1 ) , ( 2 , 2 ) ] multi_res_feature_map = tf . split ( output_conv5 , layer_depth , axis = ( - 1 if data_format == 'channels_last' else 1 ) ) for layer_ind , _depth in enumerate ( layer_depth ) : inputs = multi_res_feature_map [ layer_ind ] inputs = resnet_v2 . batch_norm_relu ( inputs , is_training , data_format ) for conv_ind , _kernel_size in enumerate ( kernel_size [ layer_ind ] ) : inputs = tf . layers . conv2d ( inputs = inputs , filters = _depth , kernel_size = _kernel_size , strides = strides [ layer_ind ] [ conv_ind ] , padding = 'SAME' , use_bias = True , activation = tf . nn . relu , kernel_initializer = initializer_to_use ( ) , data_format = data_format , name = 'conv{}_{}' . format ( layer_ind + 1 , conv_ind + 1 ) ) feat_layers . append ( inputs ) return feat_layers return model