(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_v2_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)
    inputs = 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)
    output_conv4 = xdet_block_layer(
        inputs=inputs, filters=256, block_fn=xdet_bottleneck_block, blocks=layers[2],
        dilation_rate=2, is_training=is_training, name='block_layer3',
        data_format=data_format)
    output_conv5 = xdet_block_layer(
        inputs=output_conv4, filters=512, block_fn=xdet_bottleneck_block, blocks=layers[3],
        dilation_rate=4, is_training=is_training, name='block_layer4',
        data_format=data_format)
    with tf.variable_scope('xdet_additional_conv', default_name = None, values = [output_conv5], reuse=tf.AUTO_REUSE):
      output_conv6 = xdet_block_layer(
          inputs=output_conv5, filters=512, block_fn=xdet_bottleneck_block, blocks=layers[4],
          dilation_rate=8, is_training=is_training, name='block_layer5',
          data_format=data_format)
    with tf.variable_scope('xdet_multi_path', default_name = None, values = [output_conv4, output_conv5, output_conv6], reuse=tf.AUTO_REUSE):
      output_conv4 = resnet_v2.batch_norm_relu(output_conv4, is_training, data_format)
      output_conv4 = tf.layers.conv2d(inputs=output_conv4, filters=256, kernel_size=1, strides=1,
                                  padding='SAME', use_bias=False, activation=None,
                                  kernel_initializer=conv_bn_initializer_to_use(),
                                  bias_initializer=None,#tf.zeros_initializer(),
                                  data_format=data_format)
      output_conv5 = resnet_v2.batch_norm_relu(output_conv5, is_training, data_format)
      output_conv5 = tf.layers.conv2d(inputs=output_conv5, filters=256, kernel_size=1, strides=1,
                                  padding='SAME', use_bias=False, activation=None,
                                  kernel_initializer=conv_bn_initializer_to_use(),
                                  bias_initializer=None,#tf.zeros_initializer(),
                                  data_format=data_format)
      output_conv6 = resnet_v2.batch_norm_relu(output_conv6, is_training, data_format)
      output_conv6 = tf.layers.conv2d(inputs=output_conv6, filters=256, kernel_size=1, strides=1,
                                  padding='SAME', use_bias=False, activation=None,
                                  kernel_initializer=conv_bn_initializer_to_use(),
                                  bias_initializer=None,#tf.zeros_initializer(),
                                  data_format=data_format)
      if data_format == 'channels_first':
        concat_output = tf.concat([output_conv4, output_conv5, output_conv6], axis = 1)
      else:
        concat_output = tf.concat([output_conv4, output_conv5, output_conv6], axis = -1)

      concat_output = resnet_v2.batch_norm_only(concat_output, is_training, data_format)

      with tf.variable_scope('xdet_cls_seblock', default_name = None, values = [concat_output], reuse=tf.AUTO_REUSE):
        cls_seblock_output = SEBlock(concat_output, 256 * 3, data_format, is_training)
      with tf.variable_scope('xdet_regress_seblock', default_name = None, values = [concat_output], reuse=tf.AUTO_REUSE):
        regress_seblock_output = SEBlock(concat_output, 256 * 3, data_format, is_training)

      return tf.nn.relu(concat_output * cls_seblock_output), tf.nn.relu(concat_output * regress_seblock_output)

  return model
def xdet_resnet_v2_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 ) inputs = 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 ) output_conv4 = xdet_block_layer ( inputs = inputs , filters = 256 , block_fn = xdet_bottleneck_block , blocks = layers [ 2 ] , dilation_rate = 2 , is_training = is_training , name = 'block_layer3' , data_format = data_format ) output_conv5 = xdet_block_layer ( inputs = output_conv4 , filters = 512 , block_fn = xdet_bottleneck_block , blocks = layers [ 3 ] , dilation_rate = 4 , is_training = is_training , name = 'block_layer4' , data_format = data_format ) with tf . variable_scope ( 'xdet_additional_conv' , default_name = None , values = [ output_conv5 ] , reuse = tf . AUTO_REUSE ) : output_conv6 = xdet_block_layer ( inputs = output_conv5 , filters = 512 , block_fn = xdet_bottleneck_block , blocks = layers [ 4 ] , dilation_rate = 8 , is_training = is_training , name = 'block_layer5' , data_format = data_format ) with tf . variable_scope ( 'xdet_multi_path' , default_name = None , values = [ output_conv4 , output_conv5 , output_conv6 ] , reuse = tf . AUTO_REUSE ) : output_conv4 = resnet_v2 . batch_norm_relu ( output_conv4 , is_training , data_format ) output_conv4 = tf . layers . conv2d ( inputs = output_conv4 , filters = 256 , kernel_size = 1 , strides = 1 , padding = 'SAME' , use_bias = False , activation = None , kernel_initializer = conv_bn_initializer_to_use ( ) , bias_initializer = None , #tf.zeros_initializer(), data_format = data_format ) output_conv5 = resnet_v2 . batch_norm_relu ( output_conv5 , is_training , data_format ) output_conv5 = tf . layers . conv2d ( inputs = output_conv5 , filters = 256 , kernel_size = 1 , strides = 1 , padding = 'SAME' , use_bias = False , activation = None , kernel_initializer = conv_bn_initializer_to_use ( ) , bias_initializer = None , #tf.zeros_initializer(), data_format = data_format ) output_conv6 = resnet_v2 . batch_norm_relu ( output_conv6 , is_training , data_format ) output_conv6 = tf . layers . conv2d ( inputs = output_conv6 , filters = 256 , kernel_size = 1 , strides = 1 , padding = 'SAME' , use_bias = False , activation = None , kernel_initializer = conv_bn_initializer_to_use ( ) , bias_initializer = None , #tf.zeros_initializer(), data_format = data_format ) if data_format == 'channels_first' : concat_output = tf . concat ( [ output_conv4 , output_conv5 , output_conv6 ] , axis = 1 ) else : concat_output = tf . concat ( [ output_conv4 , output_conv5 , output_conv6 ] , axis = - 1 ) concat_output = resnet_v2 . batch_norm_only ( concat_output , is_training , data_format ) with tf . variable_scope ( 'xdet_cls_seblock' , default_name = None , values = [ concat_output ] , reuse = tf . AUTO_REUSE ) : cls_seblock_output = SEBlock ( concat_output , 256 * 3 , data_format , is_training ) with tf . variable_scope ( 'xdet_regress_seblock' , default_name = None , values = [ concat_output ] , reuse = tf . AUTO_REUSE ) : regress_seblock_output = SEBlock ( concat_output , 256 * 3 , data_format , is_training ) return tf . nn . relu ( concat_output * cls_seblock_output ) , tf . nn . relu ( concat_output * regress_seblock_output ) return model