Exemple #1
0
def generator_m2(z, heads=10, training=True, reuse=True, name="generator"):

    # Network Architecture is exactly same as in infoGAN (https://arxiv.org/abs/1606.03657)
    # Architecture : FC1024_BR-FC7x7x128_BR-(64)4dc2s_BR-(1)4dc2s_S
    with tf.variable_scope(name, reuse=reuse):
        net = tf.nn.relu(
            bn(linear(z, 1024, scope='g_fc1'),
               is_training=training,
               scope='g_bn1'))
        net = tf.nn.relu(
            bn(linear(net, 128 * 7 * 7, scope='g_fc2'),
               is_training=training,
               scope='g_bn2'))
        net = tf.reshape(net, [64, 7, 7, 128])
        net = tf.nn.relu(
            bn(deconv2d(net, [64, 14, 14, 64], 4, 4, 2, 2, name='g_dc3'),
               is_training=training,
               scope='g_bn3'))

        img_sets = []
        for i in range(heads):
            out = tf.nn.sigmoid(
                deconv2d(net, [64, 28, 28, 1],
                         4,
                         4,
                         2,
                         2,
                         name='g_dc4_h' + str(i)))
            img_sets.append(out)

        return img_sets
Exemple #2
0
def discriminator2_32X32_dc(x,
                            training=True,
                            reuse=True,
                            name="discriminator"):

    # Network Architecture is exactly same as in infoGAN (https://arxiv.org/abs/1606.03657)
    # Architecture : (64)4c2s-(128)4c2s_BL-FC1024_BL-FC1_S
    with tf.variable_scope(name, reuse=reuse):
        net = lrelu(conv2d(x, 64, 4, 4, 2, 2, name='d_conv1'))
        net = lrelu(
            bn(conv2d(net, 64 * 2, 4, 4, 2, 2, name='d_conv2'),
               is_training=training,
               scope='d_bn2'))
        net = lrelu(
            bn(conv2d(net, 64 * 4, 4, 4, 2, 2, name='d_conv3'),
               is_training=training,
               scope='d_bn3'))
        net = lrelu(
            bn(conv2d(net, 64 * 8, 4, 4, 2, 2, name='d_conv4'),
               is_training=training,
               scope='d_bn4'))
        # net = tf.reshape(net, [batch_size, -1])
        # net = lrelu(bn(linear(net, 1024, scope='d_fc3'), is_training=training, scope='d_bn3'))
        # net = fc(net, 1024)
        # net = lrelu(bn(net, is_training=training, scope='d_bn5'))
        # net = fc(net, 1024)
        # net = lrelu(bn(net, is_training=training, scope='d_bn3'))
        # out_logit = linear(net, 1, scope='d_fc4')
        # out_logit = linear(tf.reshape(net, [64, -1]), 1, 'd_h4_lin')
        # out_logit = linear(net, 1, scope='d_fc4')
        # out = tf.nn.sigmoid(out_logit)
        out_logit = fc(net, 1)
        return out_logit
def mgan_dis(x, training=True, reuse=True, name = "discriminator"):
    with tf.variable_scope(name, reuse=reuse):
        net = lrelu(conv2d(x, 128, 5, 5, 2, 2, name='d_conv1'))
        net = lrelu(bn(conv2d(net, 256, 5, 5, 2, 2, name='d_conv2'), is_training=training, scope='d_bn2'))
        net = lrelu(bn(conv2d(net, 512, 5, 5, 2, 2, name='d_conv3'), is_training=training, scope='d_bn3'))
        # net = tf.reshape(net, [batch_size, -1])
        # net = lrelu(bn(linear(net, 1024, scope='d_fc3'), is_training=training, scope='d_bn3'))
        out_logit = fc(net,1)
        # net = lrelu(bn(net, is_training=training, scope='d_bn3'))
        # out_logit = linear(net, 1, scope='d_fc4')
        return out_logit
Exemple #4
0
def allconvnet_mnist(x,
                     out_dim=10,
                     name="classifier",
                     training=True,
                     reuse=True):
    # w_init = tf.variance_scaling_initializer(scale=2., mode='fan_in')
    bn = partial(batch_norm, is_training=training)
    # conv_relu = partial(conv, activation_fn=relu)#, weights_initializer=w_init)
    conv_bn_relu = partial(
        conv, activation_fn=relu, normalizer_fn=bn,
        biases_initializer=None)  #, weights_initializer=w_init)
    with tf.variable_scope(name, reuse=reuse):
        # Convolutional Layer #1
        y = conv_bn_relu(x, 64, 3, 1)
        y = conv_bn_relu(y, 64, 3, 1)
        y = conv_bn_relu(y, 64, 3, 2)
        y = conv_bn_relu(y, 128, 3, 1)
        y = conv_bn_relu(y, 128, 3, 1)
        y = conv_bn_relu(y, 128, 3, 2)
        y = conv_bn_relu(y, out_dim, 1, 1)
        # print(y.shape)

        y = tf.reduce_mean(y, [1, 2])
        y = bn(y)
        #restraint layer
        y_max = tf.reduce_max(y, axis=1, keep_dims=True)
        y = tf.exp(y - y_max)
        y = y / tf.norm(y, ord=2, axis=1, keep_dims=True)
        return y
def mgan_gen(z, heads=10,training=True, reuse=True, name = "generator"):
    with tf.variable_scope(name, reuse=reuse):
        net = tf.nn.relu(bn(linear(z, 4*4*512, scope='g_fc1'), is_training=training, scope='g_bn1'))
        # net = tf.nn.relu(bn(linear(net, 128 * 7 * 7, scope='g_fc2'), is_training=training, scope='g_bn2'))
        net = tf.reshape(net, [64, 4, 4, 512])
        net = tf.nn.relu(
            bn(deconv2d(net, [64, 8, 8, 256], 5, 5, 2, 2, name='g_dc2'), is_training=training,
               scope='g_bn2'))
        net = tf.nn.relu(
            bn(deconv2d(net, [64, 16, 16, 256], 5, 5, 2, 2, name='g_dc3'), is_training=training,
               scope='g_bn3'))
        img_sets = []
        for i in range(heads):
            out = tf.nn.sigmoid(deconv2d(net, [64, 32, 32, 3], 5, 5, 2, 2, name='g_dc4_h' + str(i)))
            img_sets.append(out)
        return img_sets
def generator_m2_32X32_dc(z, heads=10, training=True, reuse=True, name="generator"):

        # Network Architecture is exactly same as in infoGAN (https://arxiv.org/abs/1606.03657)
        # Architecture : FC1024_BR-FC7x7x128_BR-(64)4dc2s_BR-(1)4dc2s_S
    with tf.variable_scope(name, reuse=reuse):
        net = tf.nn.relu(bn(linear(z, 2048, scope='g_fc1'), is_training=training, scope='g_bn1'))
        net = tf.reshape(net, [64, 2, 2, 512])
        net = tf.nn.relu(
                bn(deconv2d(net, [64, 4, 4, 4*64], 4, 4, 2, 2, name='g_dc2'), is_training=training,
                   scope='g_bn2'))
        net = tf.nn.relu(
            bn(deconv2d(net, [64, 8, 8, 2 * 64], 4, 4, 2, 2, name='g_dc3'), is_training=training,
               scope='g_bn3'))
        net = tf.nn.relu(
            bn(deconv2d(net, [64, 16, 16, 2 * 64], 4, 4, 2, 2, name='g_dc4'), is_training=training,
               scope='g_bn4'))
        img_sets = []
        for i in range(heads):
            out = tf.nn.tanh(deconv2d(net, [64, 32, 32, 3], 4, 4, 2, 2, name='g_dc5_h' + str(i)))
            img_sets.append(out)

        return img_sets