Ejemplo n.º 1
0
def net_discriminator(input_tensor, output_dim=1, keep_prob=0.5):
    """
    To build the discriminative network
    :param input_tensor:
    :param keep_prob:
    :return:
    """
    conv_1 = layers.conv_relu_layer('conv_1',
                                    input_tensor,
                                    kernel_size=3,
                                    stride=1,
                                    output_dim=32)
    pool_1 = layers.pooling_layer('pool_1', conv_1, kernel_size=2, stride=1)
    conv_2 = layers.conv_relu_layer('conv_2',
                                    pool_1,
                                    kernel_size=3,
                                    stride=1,
                                    output_dim=32)
    pool_2 = layers.pooling_layer('pool_2', conv_2, kernel_size=2, stride=1)
    conv_3 = layers.conv_relu_layer('conv_3',
                                    pool_2,
                                    kernel_size=3,
                                    stride=1,
                                    output_dim=32)
    pool_3 = layers.pooling_layer('pool_3', conv_3, kernel_size=4, stride=1)
    fc_1 = layers.fc_relu_layer('fc_1', pool_3, output_dim=512)
    fc_1 = tf.nn.dropout(fc_1, keep_prob=keep_prob)
    fc_2 = layers.fc_relu_layer('fc_2', fc_1, output_dim=512)
    fc_2 = tf.nn.dropout(fc_2, keep_prob=keep_prob)
    fc_3 = layers.fc_layer('fc_3', fc_2, output_dim=output_dim)

    return fc_3
Ejemplo n.º 2
0
def recognition_net(input_tensor, label_size):
    """
    A recognition network as an auxiliary to the learning process.
    :param input_tensor:
    :param label_size: the number of all classes involved
    :return prob:
    """
    with tf.variable_scope(NAME_SCOPE_RECOGNITION):
        fc_1 = layers.fc_relu_layer('Fc1', input_tensor, 1024)
        fc_2 = layers.fc_relu_layer('Fc2', fc_1, 1024)
        prob = layers.fc_layer('Prob', fc_2, label_size)
    return prob
Ejemplo n.º 3
0
def generative_net(input_tensor, code_length):
    """
    A network to rebuild the data from latent representation.
    :param input_tensor:
    :param code_length: hashing length
    :return fc_3:

    """
    with tf.variable_scope(NAME_SCOPE_GENERATION):
        fc_1 = layers.fc_relu_layer('Fc1', input_tensor, 1024)
        fc_2 = layers.fc_relu_layer('Fc2', fc_1, 1024)
        fc_3 = tf.sigmoid(layers.fc_layer('Fc3', fc_2, code_length)) * 2 - 1
    return fc_3
def variational_net(input_tensor, latent_size, sub_scope):
    """
    A variational approximation of p(z) with neural network.
    :param input_tensor:
    :param latent_size: the size of the latent space
    :param sub_scope:
    :return variational_mean:
    :return variational_log_sigma:
    """
    with tf.variable_scope(NAME_SCOPE_VARIATION + '/' + sub_scope):
        fc_1 = layers.fc_relu_layer('Fc1', input_tensor, 1024)
        fc_2 = layers.fc_relu_layer('Fc2', fc_1, 1024)
        variational_mean = tf.sigmoid(layers.fc_layer('VMean', fc_2, latent_size))
        # variational_log_sigma = tf.sigmoid(layers.fc_layer('LogSigma', fc_2, latent_size))
    return variational_mean  # , variational_log_sigma