(
    in_signal,
    n_filters=[64, 128, 256, 1024],
    filter_sizes=[1],
    strides=[1],
    b_norm=True,
    b_norm_decay=0.9,
    non_linearity=tf.nn.relu,
    regularizer=None,
    weight_decay=0.001,
    symmetry=tf.reduce_max,
    dropout_prob=None,
    pool=avg_pool_1d,
    pool_sizes=None,
    scope=None,
    reuse=False,
    padding="same",
    verbose=False,
    closing=None,
    conv_op=conv_1d,
    return_layer_before_symmetry=False,
)
An Encoder (recognition network), which maps inputs onto a latent space.
An Encoder (recognition network), which maps inputs onto a latent space.
An Encoder ( recognition network ) which maps inputs onto a latent space .
def encoder_with_convs_and_symmetry(
    in_signal,
    n_filters=[64, 128, 256, 1024],
    filter_sizes=[1],
    strides=[1],
    b_norm=True,
    b_norm_decay=0.9,
    non_linearity=tf.nn.relu,
    regularizer=None,
    weight_decay=0.001,
    symmetry=tf.reduce_max,
    dropout_prob=None,
    pool=avg_pool_1d,
    pool_sizes=None,
    scope=None,
    reuse=False,
    padding="same",
    verbose=False,
    closing=None,
    conv_op=conv_1d,
    return_layer_before_symmetry=False,
):
    """An Encoder (recognition network), which maps inputs onto a latent space.
    """

    if verbose:
        print("Building Encoder")

    n_layers = len(n_filters)
    filter_sizes = replicate_parameter_for_all_layers(filter_sizes, n_layers)
    strides = replicate_parameter_for_all_layers(strides, n_layers)
    dropout_prob = replicate_parameter_for_all_layers(dropout_prob, n_layers)

    if n_layers < 2:
        raise ValueError("More than 1 layers are expected.")

    for i in range(n_layers):
        if i == 0:
            layer = in_signal

        name = "encoder_conv_layer_" + str(i)
        scope_i = expand_scope_by_name(scope, name)
        layer = conv_op(
            layer,
            nb_filter=n_filters[i],
            filter_size=filter_sizes[i],
            strides=strides[i],
            regularizer=regularizer,
            weight_decay=weight_decay,
            name=name,
            reuse=reuse,
            scope=scope_i,
            padding=padding,
        )

        if verbose:
            print(
                (
                    name,
                    "conv params = ",
                    np.prod(layer.W.get_shape().as_list())
                    + np.prod(layer.b.get_shape().as_list()),
                )
            )

        if b_norm:
            name += "_bnorm"
            scope_i = expand_scope_by_name(scope, name)
            layer = batch_normalization(
                layer, decay=b_norm_decay, name=name, reuse=reuse, scope=scope_i
            )
            if verbose:
                print(
                    (
                        "bnorm params = ",
                        np.prod(layer.beta.get_shape().as_list())
                        + np.prod(layer.gamma.get_shape().as_list()),
                    )
                )

        if non_linearity is not None:
            layer = non_linearity(layer)

        if pool is not None and pool_sizes is not None:
            if pool_sizes[i] is not None:
                layer = pool(layer, kernel_size=pool_sizes[i])

        if dropout_prob is not None and dropout_prob[i] > 0:
            layer = dropout(layer, 1.0 - dropout_prob[i])

        if verbose:
            print(layer)
            print(("output size:", np.prod(layer.get_shape().as_list()[1:]), "\n"))

    layer_before_symmetry = layer
    if symmetry is not None:
        layer = symmetry(layer, axis=1)
        if verbose:
            print(layer)

    if closing is not None:
        layer = closing(layer)
        print(layer)

    if return_layer_before_symmetry:
        return layer, layer_before_symmetry
    else:
        return layer
def encoder_with_convs_and_symmetry ( in_signal , n_filters = [ 64 , 128 , 256 , 1024 ] , filter_sizes = [ 1 ] , strides = [ 1 ] , b_norm = True , b_norm_decay = 0.9 , non_linearity = tf . nn . relu , regularizer = None , weight_decay = 0.001 , symmetry = tf . reduce_max , dropout_prob = None , pool = avg_pool_1d , pool_sizes = None , scope = None , reuse = False , padding = "same" , verbose = False , closing = None , conv_op = conv_1d , return_layer_before_symmetry = False , ) : if verbose : print ( "Building Encoder" ) n_layers = len ( n_filters ) filter_sizes = replicate_parameter_for_all_layers ( filter_sizes , n_layers ) strides = replicate_parameter_for_all_layers ( strides , n_layers ) dropout_prob = replicate_parameter_for_all_layers ( dropout_prob , n_layers ) if n_layers < 2 : raise ValueError ( "More than 1 layers are expected." ) for i in range ( n_layers ) : if i == 0 : layer = in_signal name = "encoder_conv_layer_" + str ( i ) scope_i = expand_scope_by_name ( scope , name ) layer = conv_op ( layer , nb_filter = n_filters [ i ] , filter_size = filter_sizes [ i ] , strides = strides [ i ] , regularizer = regularizer , weight_decay = weight_decay , name = name , reuse = reuse , scope = scope_i , padding = padding , ) if verbose : print ( ( name , "conv params = " , np . prod ( layer . W . get_shape ( ) . as_list ( ) ) + np . prod ( layer . b . get_shape ( ) . as_list ( ) ) , ) ) if b_norm : name += "_bnorm" scope_i = expand_scope_by_name ( scope , name ) layer = batch_normalization ( layer , decay = b_norm_decay , name = name , reuse = reuse , scope = scope_i ) if verbose : print ( ( "bnorm params = " , np . prod ( layer . beta . get_shape ( ) . as_list ( ) ) + np . prod ( layer . gamma . get_shape ( ) . as_list ( ) ) , ) ) if non_linearity is not None : layer = non_linearity ( layer ) if pool is not None and pool_sizes is not None : if pool_sizes [ i ] is not None : layer = pool ( layer , kernel_size = pool_sizes [ i ] ) if dropout_prob is not None and dropout_prob [ i ] > 0 : layer = dropout ( layer , 1.0 - dropout_prob [ i ] ) if verbose : print ( layer ) print ( ( "output size:" , np . prod ( layer . get_shape ( ) . as_list ( ) [ 1 : ] ) , "\n" ) ) layer_before_symmetry = layer if symmetry is not None : layer = symmetry ( layer , axis = 1 ) if verbose : print ( layer ) if closing is not None : layer = closing ( layer ) print ( layer ) if return_layer_before_symmetry : return layer , layer_before_symmetry else : return layer