(inputs,
                    is_training,
                    weight_decay,
                    scope='relation_module',
                    reuse=tf.AUTO_REUSE,
                    params=None,
                    moments=None,
                    depth_multiplier=1.0,
                    backprop_through_moments=True,
                    use_bounded_activation=False)
A 2-layer-convnet architecture with fully connected layers.
A 2-layer-convnet architecture with fully connected layers.
A 2 - layer - convnet architecture with fully connected layers .
def relation_module(inputs,
                    is_training,
                    weight_decay,
                    scope='relation_module',
                    reuse=tf.AUTO_REUSE,
                    params=None,
                    moments=None,
                    depth_multiplier=1.0,
                    backprop_through_moments=True,
                    use_bounded_activation=False):
  """A 2-layer-convnet architecture with fully connected layers."""
  model_params_keys, model_params_vars = [], []
  moments_keys, moments_vars = [], []
  layer = inputs
  with tf.variable_scope(scope, reuse=reuse):
    for i in range(2):
      with tf.variable_scope('layer_{}'.format(i), reuse=reuse):
        depth = int(64 * depth_multiplier)
        # Note that original has `valid` padding where we use `same`.
        layer, conv_bn_params, conv_bn_moments = conv_bn(
            layer, [3, 3],
            depth,
            1,
            weight_decay,
            params=params,
            moments=moments,
            is_training=is_training,
            backprop_through_moments=backprop_through_moments)
        model_params_keys.extend(conv_bn_params.keys())
        model_params_vars.extend(conv_bn_params.values())
        moments_keys.extend(conv_bn_moments.keys())
        moments_vars.extend(conv_bn_moments.values())

      layer = relu(layer, use_bounded_activation=use_bounded_activation)
      # This is a hacky way preventing max pooling if the spatial dimensions
      # are already reduced.
      if layer.shape[1] > 1:
        layer = tf.layers.max_pooling2d(layer, [2, 2], 2)
      tf.logging.info('Output of block %d: %s' % (i, layer.shape))

    layer = tf.layers.flatten(layer)
    relu_activation_fn = functools.partial(
        relu, use_bounded_activation=use_bounded_activation)
    with tf.variable_scope('layer_2_fc', reuse=reuse):
      layer, dense_params = dense(
          layer, 8, weight_decay, activation_fn=relu_activation_fn)
      tf.logging.info('Output layer_2_fc: %s' % layer.shape)
      model_params_keys.extend(dense_params.keys())
      model_params_vars.extend(dense_params.values())
    with tf.variable_scope('layer_3_fc', reuse=reuse):
      output, dense_params = dense(
          layer, 1, weight_decay, activation_fn=tf.nn.sigmoid)
      tf.logging.info('Output layer_3_fc: %s' % output.shape)
      model_params_keys.extend(dense_params.keys())
      model_params_vars.extend(dense_params.values())

    model_params = collections.OrderedDict(
        zip(model_params_keys, model_params_vars))
    moments = collections.OrderedDict(zip(moments_keys, moments_vars))
    return_dict = {'output': output, 'params': model_params, 'moments': moments}

    return return_dict
def relation_module ( inputs , is_training , weight_decay , scope = 'relation_module' , reuse = tf . AUTO_REUSE , params = None , moments = None , depth_multiplier = 1.0 , backprop_through_moments = True , use_bounded_activation = False ) : model_params_keys , model_params_vars = [ ] , [ ] moments_keys , moments_vars = [ ] , [ ] layer = inputs with tf . variable_scope ( scope , reuse = reuse ) : for i in range ( 2 ) : with tf . variable_scope ( 'layer_{}' . format ( i ) , reuse = reuse ) : depth = int ( 64 * depth_multiplier ) # Note that original has `valid` padding where we use `same`. layer , conv_bn_params , conv_bn_moments = conv_bn ( layer , [ 3 , 3 ] , depth , 1 , weight_decay , params = params , moments = moments , is_training = is_training , backprop_through_moments = backprop_through_moments ) model_params_keys . extend ( conv_bn_params . keys ( ) ) model_params_vars . extend ( conv_bn_params . values ( ) ) moments_keys . extend ( conv_bn_moments . keys ( ) ) moments_vars . extend ( conv_bn_moments . values ( ) ) layer = relu ( layer , use_bounded_activation = use_bounded_activation ) # This is a hacky way preventing max pooling if the spatial dimensions # are already reduced. if layer . shape [ 1 ] > 1 : layer = tf . layers . max_pooling2d ( layer , [ 2 , 2 ] , 2 ) tf . logging . info ( 'Output of block %d: %s' % ( i , layer . shape ) ) layer = tf . layers . flatten ( layer ) relu_activation_fn = functools . partial ( relu , use_bounded_activation = use_bounded_activation ) with tf . variable_scope ( 'layer_2_fc' , reuse = reuse ) : layer , dense_params = dense ( layer , 8 , weight_decay , activation_fn = relu_activation_fn ) tf . logging . info ( 'Output layer_2_fc: %s' % layer . shape ) model_params_keys . extend ( dense_params . keys ( ) ) model_params_vars . extend ( dense_params . values ( ) ) with tf . variable_scope ( 'layer_3_fc' , reuse = reuse ) : output , dense_params = dense ( layer , 1 , weight_decay , activation_fn = tf . nn . sigmoid ) tf . logging . info ( 'Output layer_3_fc: %s' % output . shape ) model_params_keys . extend ( dense_params . keys ( ) ) model_params_vars . extend ( dense_params . values ( ) ) model_params = collections . OrderedDict ( zip ( model_params_keys , model_params_vars ) ) moments = collections . OrderedDict ( zip ( moments_keys , moments_vars ) ) return_dict = { 'output' : output , 'params' : model_params , 'moments' : moments } return return_dict