(
    x,
    depth,
    stride,
    weight_decay,
    params=None,
    moments=None,
    use_project=False,
    backprop_through_moments=True,
    is_training=True,
    input_rate=1,
    output_rate=1,
    use_bounded_activation=False,
    film_selector=None
)
return x, params, moments
ResNet18 residual block.
ResNet18 residual block.
ResNet18 residual block .
def bottleneck(
    x,
    depth,
    stride,
    weight_decay,
    params=None,
    moments=None,
    use_project=False,
    backprop_through_moments=True,
    is_training=True,
    input_rate=1,
    output_rate=1,
    use_bounded_activation=False,
    film_selector=None
):
  """ResNet18 residual block."""
  params_keys, params_vars = [], []
  moments_keys, moments_vars = [], []  # means and vars of different layers.
  with tf.variable_scope('conv1'):
    h, conv_bn_params, conv_bn_moments = conv_bn(
        x,
        [3, 3],
        depth[0],
        stride,
        weight_decay,
        params=params,
        moments=moments,
        is_training=is_training,
        rate=input_rate,
        backprop_through_moments=backprop_through_moments,
        film_selector=film_selector
    )
    params_keys.extend(conv_bn_params.keys())
    params_vars.extend(conv_bn_params.values())
    moments_keys.extend(conv_bn_moments.keys())
    moments_vars.extend(conv_bn_moments.values())

    h = relu(h, use_bounded_activation=use_bounded_activation)

  with tf.variable_scope('conv2'):
    h, conv_bn_params, conv_bn_moments = conv_bn(
        h,
        [3, 3],
        depth[1],
        stride=1,
        weight_decay=weight_decay,
        params=params,
        moments=moments,
        is_training=is_training,
        rate=output_rate,
        backprop_through_moments=backprop_through_moments,
        film_selector=film_selector
    )
    if use_bounded_activation:
      h = tf.clip_by_value(h, -6.0, 6.0)

    params_keys.extend(conv_bn_params.keys())
    params_vars.extend(conv_bn_params.values())
    moments_keys.extend(conv_bn_moments.keys())
    moments_vars.extend(conv_bn_moments.values())

  with tf.variable_scope('identity'):
    if use_project:
      with tf.variable_scope('projection_conv'):
        x, conv_bn_params, conv_bn_moments = conv_bn(
            x,
            [1, 1],
            depth[1],
            stride,
            weight_decay,
            params=params,
            moments=moments,
            is_training=is_training,
            rate=1,
            backprop_through_moments=backprop_through_moments,
            film_selector=film_selector
        )
        params_keys.extend(conv_bn_params.keys())
        params_vars.extend(conv_bn_params.values())
        moments_keys.extend(conv_bn_moments.keys())
        moments_vars.extend(conv_bn_moments.values())
    x = relu(x + h, use_bounded_activation=use_bounded_activation)

  params = collections.OrderedDict(zip(params_keys, params_vars))
  moments = collections.OrderedDict(zip(moments_keys, moments_vars))
  return x, params, moments
def bottleneck ( x , depth , stride , weight_decay , params = None , moments = None , use_project = False , backprop_through_moments = True , is_training = True , input_rate = 1 , output_rate = 1 , use_bounded_activation = False , film_selector = None ) : params_keys , params_vars = [ ] , [ ] moments_keys , moments_vars = [ ] , [ ] # means and vars of different layers. with tf . variable_scope ( 'conv1' ) : h , conv_bn_params , conv_bn_moments = conv_bn ( x , [ 3 , 3 ] , depth [ 0 ] , stride , weight_decay , params = params , moments = moments , is_training = is_training , rate = input_rate , backprop_through_moments = backprop_through_moments , film_selector = film_selector ) params_keys . extend ( conv_bn_params . keys ( ) ) params_vars . extend ( conv_bn_params . values ( ) ) moments_keys . extend ( conv_bn_moments . keys ( ) ) moments_vars . extend ( conv_bn_moments . values ( ) ) h = relu ( h , use_bounded_activation = use_bounded_activation ) with tf . variable_scope ( 'conv2' ) : h , conv_bn_params , conv_bn_moments = conv_bn ( h , [ 3 , 3 ] , depth [ 1 ] , stride = 1 , weight_decay = weight_decay , params = params , moments = moments , is_training = is_training , rate = output_rate , backprop_through_moments = backprop_through_moments , film_selector = film_selector ) if use_bounded_activation : h = tf . clip_by_value ( h , - 6.0 , 6.0 ) params_keys . extend ( conv_bn_params . keys ( ) ) params_vars . extend ( conv_bn_params . values ( ) ) moments_keys . extend ( conv_bn_moments . keys ( ) ) moments_vars . extend ( conv_bn_moments . values ( ) ) with tf . variable_scope ( 'identity' ) : if use_project : with tf . variable_scope ( 'projection_conv' ) : x , conv_bn_params , conv_bn_moments = conv_bn ( x , [ 1 , 1 ] , depth [ 1 ] , stride , weight_decay , params = params , moments = moments , is_training = is_training , rate = 1 , backprop_through_moments = backprop_through_moments , film_selector = film_selector ) params_keys . extend ( conv_bn_params . keys ( ) ) params_vars . extend ( conv_bn_params . values ( ) ) moments_keys . extend ( conv_bn_moments . keys ( ) ) moments_vars . extend ( conv_bn_moments . values ( ) ) x = relu ( x + h , use_bounded_activation = use_bounded_activation ) params = collections . OrderedDict ( zip ( params_keys , params_vars ) ) moments = collections . OrderedDict ( zip ( moments_keys , moments_vars ) ) return x , params , moments