Beispiel #1
0
def create_generator(Xin,
                     is_training,
                     Cout=1,
                     reuse=False,
                     networktype='ganG'):
    '''input : batchsize * latentD
       output: batchsize * 28 * 28 * 1'''
    with tf.variable_scope(networktype, reuse=reuse):
        Xout = dense(Xin,
                     is_training,
                     Cout=7 * 7 * 256,
                     act='reLu',
                     norm='batchnorm',
                     name='dense1')
        Xout = tf.reshape(Xout, shape=[-1, 7, 7, 256])  # 7
        Xout = deconv(Xout,
                      is_training,
                      kernel_w=4,
                      stride=2,
                      epf=2,
                      Cout=128,
                      act='reLu',
                      norm='batchnorm',
                      name='deconv1')  # 14
        Xout = deconv(Xout,
                      is_training,
                      kernel_w=4,
                      stride=2,
                      epf=2,
                      Cout=Cout,
                      act=None,
                      norm=None,
                      name='deconv2')  # 28
        Xout = tf.nn.sigmoid(Xout)
    return Xout
Beispiel #2
0
def create_encoder(Xin,
                   is_training,
                   latentD,
                   reuse=False,
                   networktype='cdaeE'):
    '''Xin: batchsize * H * W * Cin
       output1-2: batchsize * Cout'''
    with tf.variable_scope(networktype, reuse=reuse):
        Xout = conv(Xin,
                    is_training,
                    kernel_w=4,
                    stride=2,
                    Cout=64,
                    pad=1,
                    act='reLu',
                    norm='batchnorm',
                    name='conv1')  # 14*14
        Xout = conv(Xout,
                    is_training,
                    kernel_w=4,
                    stride=2,
                    Cout=128,
                    pad=1,
                    act='reLu',
                    norm='batchnorm',
                    name='conv2')  # 7*7
        Xout = dense(Xout,
                     is_training,
                     Cout=latentD,
                     act=None,
                     norm=None,
                     name='dense_mean')
    return Xout
Beispiel #3
0
def create_decoder(Xin,
                   is_training,
                   latentD,
                   Cout=1,
                   reuse=False,
                   networktype='cdaeD'):
    with tf.variable_scope(networktype, reuse=reuse):
        Xout = dense(Xin,
                     is_training,
                     Cout=7 * 7 * 256,
                     act='reLu',
                     norm='batchnorm',
                     name='dense1')
        Xout = tf.reshape(Xout, shape=[-1, 7, 7, 256])  # 7
        Xout = deconv(Xout,
                      is_training,
                      kernel_w=4,
                      stride=2,
                      Cout=256,
                      epf=2,
                      act='reLu',
                      norm='batchnorm',
                      name='deconv1')  # 14
        Xout = deconv(Xout,
                      is_training,
                      kernel_w=4,
                      stride=2,
                      Cout=Cout,
                      epf=2,
                      act=None,
                      norm=None,
                      name='deconv2')  # 28
        Xout = tf.nn.sigmoid(Xout)
    return Xout
Beispiel #4
0
def create_gan_G(z,
                 is_training,
                 Cout=1,
                 trainable=True,
                 reuse=False,
                 networktype='ganG'):
    '''input : batchsize * latentDim
       output: batchsize * 28 * 28 * 1'''
    with tf.variable_scope(networktype, reuse=reuse):
        Gout = dense(z,
                     is_training,
                     Cout=7 * 7 * 256,
                     trainable=trainable,
                     act='reLu',
                     norm='batchnorm',
                     name='dense1')
        Gout = tf.reshape(Gout, shape=[-1, 7, 7, 256])  # 7
        Gout = deconv(Gout,
                      is_training,
                      kernel_w=4,
                      stride=2,
                      epf=2,
                      Cout=128,
                      trainable=trainable,
                      act='reLu',
                      norm='batchnorm',
                      name='deconv1')  # 14
        Gout = deconv(Gout,
                      is_training,
                      kernel_w=4,
                      stride=2,
                      epf=2,
                      Cout=Cout,
                      trainable=trainable,
                      act=None,
                      norm=None,
                      name='deconv2')  # 28
        Gout = tf.nn.sigmoid(Gout)
    return Gout
Beispiel #5
0
def create_discriminator(Xin, is_training, reuse=False, networktype='ganD'):
    with tf.variable_scope(networktype, reuse=reuse):
        Xout = dense(Xin,
                     is_training,
                     Cout=7 * 7 * 256,
                     act='reLu',
                     norm='batchnorm',
                     name='dense1')
        Xout = tf.reshape(Xout, shape=[-1, 7, 7, 256])  # 7
        Xout = conv(Xout,
                    is_training,
                    kernel_w=3,
                    stride=1,
                    pad=1,
                    Cout=128,
                    act='lrelu',
                    norm='batchnorm',
                    name='conv1')  # 7
        Xout = conv(Xout,
                    is_training,
                    kernel_w=3,
                    stride=1,
                    pad=1,
                    Cout=256,
                    act='lrelu',
                    norm='batchnorm',
                    name='conv2')  # 7
        Xout = conv(Xout,
                    is_training,
                    kernel_w=3,
                    stride=1,
                    pad=None,
                    Cout=1,
                    act=None,
                    norm='batchnorm',
                    name='conv3')  # 5
        Xout = tf.nn.sigmoid(Xout)
    return Xout