Example #1
0
def generator(observed, n, n_z, is_training):
    with zs.BayesianNet(observed=observed) as generator:
        z_min = -tf.ones([n, n_z])
        z_max = tf.ones([n, n_z])
        z = zs.Uniform('z', z_min, z_max)
        lx_z = tf.reshape(z, [-1, 1, 1, n_z])
        ngf = 32
        lx_z = tf.layers.conv2d_transpose(lx_z, ngf * 4, 3, use_bias=False)
        lx_z = tf.layers.batch_normalization(lx_z,
                                             training=is_training,
                                             scale=False)
        lx_z = tf.nn.relu(lx_z)
        lx_z = tf.layers.conv2d_transpose(lx_z, ngf * 2, 5, use_bias=False)
        lx_z = tf.layers.batch_normalization(lx_z,
                                             training=is_training,
                                             scale=False)
        lx_z = tf.nn.relu(lx_z)
        lx_z = tf.layers.conv2d_transpose(lx_z,
                                          ngf,
                                          5,
                                          strides=(2, 2),
                                          padding='same',
                                          use_bias=False)
        lx_z = tf.layers.batch_normalization(lx_z,
                                             training=is_training,
                                             scale=False)
        lx_z = tf.nn.relu(lx_z)
        lx_z = tf.layers.conv2d_transpose(lx_z,
                                          1,
                                          5,
                                          strides=(2, 2),
                                          padding='same',
                                          activation=tf.sigmoid)
    return generator, lx_z
Example #2
0
def generator(observed, n, n_z, is_training):
    with zs.BayesianNet(observed=observed) as generator:
        normalizer_params = {
            'is_training': is_training,
            'updates_collections': None
        }
        ngf = 64
        z_min = -tf.ones([n, n_z])
        z_max = tf.ones([n, n_z])
        z = zs.Uniform('z', z_min, z_max)
        lx_z = layers.fully_connected(z,
                                      num_outputs=ngf * 8 * 4 * 4,
                                      normalizer_fn=layers.batch_norm,
                                      normalizer_params=normalizer_params)
        lx_z = tf.reshape(lx_z, [-1, 4, 4, ngf * 8])
        lx_z = layers.conv2d_transpose(lx_z,
                                       ngf * 4,
                                       5,
                                       stride=2,
                                       normalizer_fn=layers.batch_norm,
                                       normalizer_params=normalizer_params)
        lx_z = layers.conv2d_transpose(lx_z,
                                       ngf * 2,
                                       5,
                                       stride=2,
                                       normalizer_fn=layers.batch_norm,
                                       normalizer_params=normalizer_params)
        lx_z = layers.conv2d_transpose(lx_z,
                                       3,
                                       5,
                                       stride=2,
                                       activation_fn=tf.nn.sigmoid)
    return generator, lx_z
Example #3
0
def generator(observed, n, n_z, is_training):
    with zs.BayesianNet(observed=observed) as generator:
        normalizer_params = {
            'is_training': is_training,
            'updates_collections': None
        }
        z_min = -tf.ones([n, n_z])
        z_max = tf.ones([n, n_z])
        z = zs.Uniform('z', z_min, z_max)
        lx_z = tf.reshape(z, [-1, 1, 1, n_z])
        ngf = 32
        lx_z = layers.conv2d_transpose(lx_z,
                                       ngf * 4,
                                       3,
                                       padding='VALID',
                                       normalizer_fn=layers.batch_norm,
                                       normalizer_params=normalizer_params)
        lx_z = layers.conv2d_transpose(lx_z,
                                       ngf * 2,
                                       5,
                                       padding='VALID',
                                       normalizer_fn=layers.batch_norm,
                                       normalizer_params=normalizer_params)
        lx_z = layers.conv2d_transpose(lx_z,
                                       ngf,
                                       5,
                                       stride=2,
                                       normalizer_fn=layers.batch_norm,
                                       normalizer_params=normalizer_params)
        lx_z = layers.conv2d_transpose(lx_z,
                                       1,
                                       5,
                                       stride=2,
                                       activation_fn=tf.nn.sigmoid)
    return generator, lx_z