예제 #1
0
def discriminator(dis_inputs, is_training=True):
    # Define the discriminator block
    def discriminator_block(inputs, output_channel, kernel_size, stride,
                            scope):
        with tf.variable_scope(scope):
            net = conv2(inputs,
                        kernel_size,
                        output_channel,
                        stride,
                        use_bias=False,
                        scope='conv1')
            # net = batchnorm(net, is_training)
            net = lrelu(net, 0.2)

        return net

    with tf.variable_scope('discriminator_unit'):
        # The input layer
        with tf.variable_scope('input_stage'):
            net = conv2(dis_inputs, 3, 64, 1, scope='conv')
            net = lrelu(net, 0.2)

        # The discriminator block part
        # block 1
        net = discriminator_block(net, 64, 3, 2, 'disblock_1')

        # block 2
        net = discriminator_block(net, 128, 3, 1, 'disblock_2')

        # block 3
        net = discriminator_block(net, 128, 3, 2, 'disblock_3')

        # block 4
        net = discriminator_block(net, 256, 3, 1, 'disblock_4')

        # block 5
        net = discriminator_block(net, 256, 3, 2, 'disblock_5')

        # block 6
        net = discriminator_block(net, 512, 3, 1, 'disblock_6')

        # block_7
        net = discriminator_block(net, 512, 3, 2, 'disblock_7')

        # The dense layer 1
        with tf.variable_scope('dense_layer_1'):
            net = slim.flatten(net)
            net = denselayer(net, 1024)
            net = lrelu(net, 0.2)

        # The dense layer 2
        with tf.variable_scope('dense_layer_2'):
            logits = denselayer(net, 1)
            prob = tf.nn.sigmoid(logits)

    return logits, prob
예제 #2
0
def discriminatorDense(dis_inputs, is_training=True):
    # Define the discriminator block
    def discriminator_block(inputs, output_channel, kernel_size, stride, scope):
        with tf.variable_scope(scope):
            net = conv2(inputs, kernel_size, output_channel, stride, use_bias=False, scope='conv1')
            # net = batchnorm(net, is_training)
            net = lrelu(net, 0.2)
        return net

    with tf.variable_scope('discriminator_unit'):
        # The input layer
        with tf.variable_scope('input_stage'):
            net = conv2(dis_inputs, 3, 64, 1, scope='conv')
            net = lrelu(net, 0.2)

        # The discriminator block part
        # block 1
        net = discriminator_block(net, 64, 3, 2, 'disblock_1')

        # block 2
        net = discriminator_block(net, 64, 3, 2, 'disblock_2')

        # block 3
        net = discriminator_block(net, 64, 3, 1, 'disblock_3')

        # The dense block part
        # Define the denseblock configuration
        layer_per_block = 8
        bottleneck_scale = 4
        growth_rate = 12
        transition_output_channel = 128
        with tf.variable_scope('denseBlock_1'):
            net = denseBlock(net, layer_per_block, bottleneck_scale, growth_rate, is_training)

        with tf.variable_scope('transition_layer_1'):
            net = transitionLayer(net, transition_output_channel, is_training)

        # The dense layer 1
        with tf.variable_scope('dense_layer_1'):
            net = slim.flatten(net)
            net = denselayer(net, 1024)
            net = lrelu(net, 0.2)

        # The dense layer 2
        with tf.variable_scope('dense_layer_2'):
            net = denselayer(net, 1)
            net = tf.nn.sigmoid(net)
    return net
예제 #3
0
def discriminator_emb(dis_embeddings, is_training=True):
    # Define the discriminator block
    def discriminator_block(inputs, output_channel, scope):
        with tf.variable_scope(scope):
            net = denselayer(inputs, output_channel)
            net = lrelu(net, 0.2)
        return net

    with tf.variable_scope('discriminator_unit'):
        # The discriminator block part
        # block 1
        net = discriminator_block(dis_embeddings, 1024, 'disblock_1')

        # block 2
        net = discriminator_block(net, 1024, 'disblock_2')

        # block 3
        net = discriminator_block(net, 512, 'disblock_3')

        # block 4
        net = discriminator_block(net, 512, 'disblock_4')

        # The dense layer 1
        with tf.variable_scope('dense_layer_1'):
            net = denselayer(net, 128)
            net = lrelu(net, 0.2)

        # The dense layer 2
        with tf.variable_scope('dense_layer_2'):
            net = denselayer(net, 1)
            net = tf.nn.sigmoid(net)

    return net
예제 #4
0
파일: frvsr.py 프로젝트: hotstaff/TecoGAN
def fnet(fnet_input, reuse=False):
    def down_block(inputs, output_channel=64, stride=1, scope='down_block'):
        with tf.compat.v1.variable_scope(scope):
            net = conv2(inputs,
                        3,
                        output_channel,
                        stride,
                        use_bias=True,
                        scope='conv_1')
            net = lrelu(net, 0.2)
            net = conv2(net,
                        3,
                        output_channel,
                        stride,
                        use_bias=True,
                        scope='conv_2')
            net = lrelu(net, 0.2)
            net = maxpool(net)

        return net

    def up_block(inputs, output_channel=64, stride=1, scope='up_block'):
        with tf.compat.v1.variable_scope(scope):
            net = conv2(inputs,
                        3,
                        output_channel,
                        stride,
                        use_bias=True,
                        scope='conv_1')
            net = lrelu(net, 0.2)
            net = conv2(net,
                        3,
                        output_channel,
                        stride,
                        use_bias=True,
                        scope='conv_2')
            net = lrelu(net, 0.2)
            new_shape = tf.shape(net)[1:-1] * 2
            net = tf.image.resize(net, new_shape)

        return net

    with tf.compat.v1.variable_scope('autoencode_unit', reuse=reuse):
        net = down_block(fnet_input, 32, scope='encoder_1')
        net = down_block(net, 64, scope='encoder_2')
        net = down_block(net, 128, scope='encoder_3')

        net = up_block(net, 256, scope='decoder_1')
        net = up_block(net, 128, scope='decoder_2')
        net1 = up_block(net, 64, scope='decoder_3')

        with tf.compat.v1.variable_scope('output_stage'):
            net = conv2(net1, 3, 32, 1, scope='conv1')
            net = lrelu(net, 0.2)
            net2 = conv2(net, 3, 2, 1, scope='conv2')
            net = tf.tanh(net2) * 24.0
            # the 24.0 is the max Velocity, details can be found in TecoGAN paper
    return net
예제 #5
0
파일: frvsr.py 프로젝트: hotstaff/TecoGAN
    def down_block(inputs, output_channel=64, stride=1, scope='down_block'):
        with tf.compat.v1.variable_scope(scope):
            net = conv2(inputs,
                        3,
                        output_channel,
                        stride,
                        use_bias=True,
                        scope='conv_1')
            net = lrelu(net, 0.2)
            net = conv2(net,
                        3,
                        output_channel,
                        stride,
                        use_bias=True,
                        scope='conv_2')
            net = lrelu(net, 0.2)
            net = maxpool(net)

        return net
예제 #6
0
파일: frvsr.py 프로젝트: hotstaff/TecoGAN
    def up_block(inputs, output_channel=64, stride=1, scope='up_block'):
        with tf.compat.v1.variable_scope(scope):
            net = conv2(inputs,
                        3,
                        output_channel,
                        stride,
                        use_bias=True,
                        scope='conv_1')
            net = lrelu(net, 0.2)
            net = conv2(net,
                        3,
                        output_channel,
                        stride,
                        use_bias=True,
                        scope='conv_2')
            net = lrelu(net, 0.2)
            new_shape = tf.shape(net)[1:-1] * 2
            net = tf.image.resize(net, new_shape)

        return net
예제 #7
0
    def discriminator_block(inputs, output_channel, kernel_size, stride,
                            scope):
        with tf.variable_scope(scope):
            net = conv2(inputs,
                        kernel_size,
                        output_channel,
                        stride,
                        use_bias=False,
                        scope='conv1')
            # net = batchnorm(net, is_training)
            net = lrelu(net, 0.2)

        return net
예제 #8
0
    def discriminator_block(inputs, output_channel, kernel_size, stride,
                            scope):
        with tf.variable_scope(scope):
            net = ops.conv3d(inputs,
                             kernel_size,
                             output_channel,
                             stride,
                             use_bias=False,
                             scope='conv1')
            if (FLAGS.GAN_type == 'GAN'):
                net = ops.batchnorm(net, FLAGS.is_training)
            net = ops.lrelu(net, 0.2)

        return net
예제 #9
0
def discriminator_feature(dis_features, is_training=True):
    # Define the discriminator block
    def discriminator_block(inputs, output_channel, kernel_size, stride,
                            scope):
        with tf.variable_scope(scope):
            net = conv2(inputs,
                        kernel_size,
                        output_channel,
                        stride,
                        use_bias=False,
                        scope='conv1')
            # net = batchnorm(net, is_training)
            net = lrelu(net, 0.2)

        return net

    with tf.variable_scope('discriminator_unit'):
        # The discriminator block part
        # block 1
        net = discriminator_block(dis_features, 256, 3, 1, 'disblock_1')

        # block 2
        net = discriminator_block(net, 256, 3, 2, 'disblock_2')

        # block 3
        net = discriminator_block(net, 512, 3, 1, 'disblock_3')

        # block 4
        net = discriminator_block(net, 512, 3, 2, 'disblock_4')

        # The dense layer 1
        with tf.variable_scope('dense_layer_1'):
            net = slim.flatten(net)
            net = denselayer(net, 1024)
            net = lrelu(net, 0.2)

        # The dense layer 2
        with tf.variable_scope('dense_layer_2'):
            net = denselayer(net, 1)
            net = tf.nn.sigmoid(net)

    return net
예제 #10
0
def discriminator(dis_inputs, FLAGS=None):
    if FLAGS is None:
        raise ValueError('No FLAGS is provided for discriminator')

    # Define the discriminator block
    def discriminator_block(inputs, output_channel, kernel_size, stride,
                            scope):
        with tf.variable_scope(scope):
            net = ops.conv3d(inputs,
                             kernel_size,
                             output_channel,
                             stride,
                             use_bias=False,
                             scope='conv1')
            if (FLAGS.GAN_type == 'GAN'):
                net = ops.batchnorm(net, FLAGS.is_training)
            net = ops.lrelu(net, 0.2)

        return net

    # with tf.device('/gpu:0'):
    with tf.variable_scope('discriminator_unit'):
        # The input layer
        with tf.variable_scope('input_stage'):
            net = ops.conv3d(dis_inputs, 3, 64, 1, scope='conv')
            net = ops.lrelu(net, 0.2)  # (m, 64, 64, 64, 64)

        # The discriminator block part
        # block 1
        net = discriminator_block(net, 64, 3, 2,
                                  'disblock_1')  # (m, 32, 32, 32, 64)

        # block 2
        net = discriminator_block(net, 128, 3, 1,
                                  'disblock_2')  # (m, 32, 32, 32, 128)

        # block 3
        net = discriminator_block(net, 128, 3, 2,
                                  'disblock_3')  # (m, 16, 16, 16, 128)

        # block 4
        net = discriminator_block(net, 256, 3, 1,
                                  'disblock_4')  # (m, 16, 16, 16, 256)

        # block 5
        net = discriminator_block(net, 256, 3, 2,
                                  'disblock_5')  # (m, 8, 8, 8, 256)

        # block 6
        net = discriminator_block(net, 512, 3, 1,
                                  'disblock_6')  # (m, 8, 8, 8, 512)

        # block_7
        net = discriminator_block(net, 512, 3, 2,
                                  'disblock_7')  # (m, 4, 4, 4, 512)

        # block_8
        net = discriminator_block(net, 1024, 3, 1,
                                  'disblock_8')  # (m, 4, 4, 4, 1024)

        # block_9
        net = discriminator_block(net, 1024, 3, 2,
                                  'disblock_9')  # (m, 2, 2, 2, 1024)

        # The dense layer 1
        with tf.variable_scope('dense_layer_1'):
            net = tf.contrib.layers.flatten(net)
            net = ops.denselayer(net, 1024)
            net = ops.lrelu(net, 0.2)

        # The dense layer 2
        with tf.variable_scope('dense_layer_2'):
            net = ops.denselayer(net, 1)
            net = tf.nn.sigmoid(net)

    return net
예제 #11
0
 def discriminator_block(inputs, output_channel, scope):
     with tf.variable_scope(scope):
         net = denselayer(inputs, output_channel)
         net = lrelu(net, 0.2)
     return net