(block_fn, layers, num_classes,
                                 data_format=None)
return model
Generator for ImageNet 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.
    num_classes: The number of possible classes for image classification.
    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 ImageNet ResNet v2 models.
Generator for ImageNet ResNet v2 models .
def imagenet_resnet_v2_generator(block_fn, layers, num_classes,
                                 data_format=None):
  """Generator for ImageNet 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.
    num_classes: The number of possible classes for image classification.
    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."""
    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 = conv2d_fixed_padding(
        inputs=inputs, filters=64, kernel_size=7, strides=2,
        data_format=data_format)
    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 = 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 = 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)

    inputs = 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)
    inputs = xdet_block_layer(
        inputs=inputs, 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 = [inputs], reuse=tf.AUTO_REUSE):
    #   inputs = xdet_block_layer(
    #       inputs=inputs, filters=512, block_fn=xdet_bottleneck_block, blocks=layers[4],
    #       dilation_rate=8, is_training=is_training, name='block_layer5',
    #       data_format=data_format)


    # inputs = block_layer(
    #     inputs=inputs, filters=256, block_fn=block_fn, blocks=layers[2],
    #     strides=2, is_training=is_training, name='block_layer3',
    #     data_format=data_format)
    # inputs = block_layer(
    #     inputs=inputs, filters=512, block_fn=block_fn, blocks=layers[3],
    #     strides=2, is_training=is_training, name='block_layer4',
    #     data_format=data_format)

    inputs = batch_norm_relu(inputs, is_training, data_format)
    inputs = tf.layers.average_pooling2d(
        inputs=inputs, pool_size=28, strides=1, padding='VALID',
        data_format=data_format)
    inputs = tf.identity(inputs, 'final_avg_pool')
    inputs = tf.reshape(inputs,
                        [-1, 512 if block_fn is building_block else 2048])
    inputs = tf.layers.dense(inputs=inputs, units=num_classes)
    inputs = tf.identity(inputs, 'final_dense')
    return inputs

  return model
def imagenet_resnet_v2_generator ( block_fn , layers , num_classes , 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.""" 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 = conv2d_fixed_padding ( inputs = inputs , filters = 64 , kernel_size = 7 , strides = 2 , data_format = data_format ) 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 = 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 = 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 ) inputs = 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 ) inputs = xdet_block_layer ( inputs = inputs , 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 = [inputs], reuse=tf.AUTO_REUSE): #   inputs = xdet_block_layer( #       inputs=inputs, filters=512, block_fn=xdet_bottleneck_block, blocks=layers[4], #       dilation_rate=8, is_training=is_training, name='block_layer5', #       data_format=data_format) # inputs = block_layer( #     inputs=inputs, filters=256, block_fn=block_fn, blocks=layers[2], #     strides=2, is_training=is_training, name='block_layer3', #     data_format=data_format) # inputs = block_layer( #     inputs=inputs, filters=512, block_fn=block_fn, blocks=layers[3], #     strides=2, is_training=is_training, name='block_layer4', #     data_format=data_format) inputs = batch_norm_relu ( inputs , is_training , data_format ) inputs = tf . layers . average_pooling2d ( inputs = inputs , pool_size = 28 , strides = 1 , padding = 'VALID' , data_format = data_format ) inputs = tf . identity ( inputs , 'final_avg_pool' ) inputs = tf . reshape ( inputs , [ - 1 , 512 if block_fn is building_block else 2048 ] ) inputs = tf . layers . dense ( inputs = inputs , units = num_classes ) inputs = tf . identity ( inputs , 'final_dense' ) return inputs return model