コード例 #1
0
ファイル: layers.py プロジェクト: gdahia/DLF
def split2d_prior(z, hps):
    n_z2 = int(z.get_shape()[3])
    n_z1 = n_z2

    h = conv2d_zeros(z, 2 * n_z1, name="conv")
    mean, logsd = tf.split(h, 2, axis=-1)

    rescale = tf.get_variable("rescale", [], initializer=tf.constant_initializer(1.))
    scale_shift = tf.get_variable("scale_shift", [], initializer=tf.constant_initializer(0.))
    logsd = tf.tanh(logsd) * rescale + scale_shift

    return gaussian_diag(mean, logsd)
コード例 #2
0
ファイル: layers.py プロジェクト: winwinJJiang/DLF
def split2d_prior(z, hps):
    n_z2 = int(z.get_shape()[3])
    n_z1 = n_z2

    h = conv2d_zeros(z, 2 * n_z1, name="conv")
    mean, logsd = tf.split(h, 2, axis=-1)

    rescale = tf.get_variable("rescale", [],
                              initializer=tf.constant_initializer(1.))
    scale_shift = tf.get_variable("scale_shift", [],
                                  initializer=tf.constant_initializer(0.))
    logsd = tf.tanh(logsd) * rescale + scale_shift

    return gaussian_diag(mean, logsd)
コード例 #3
0
ファイル: layers.py プロジェクト: gdahia/DLF
def prior(y_onehot, hps, name=None):
    n_z = hps.top_shape[-1]

    h = tf.zeros([tf.shape(y_onehot)[0]]+hps.top_shape[:2]+[2*n_z])
    h = conv2d_zeros(h, 2*n_z, name="p")
    if hps.ycond:
        h += tf.reshape(linear_zeros(y_onehot, 2*n_z, name="y_emb"), [-1, 1, 1, 2 * n_z])
    mean, logsd = tf.split(h, 2, axis=-1)

    rescale = tf.get_variable("rescale", [], initializer=tf.constant_initializer(1.))
    scale_shift = tf.get_variable("scale_shift", [], initializer=tf.constant_initializer(0.))
    logsd = tf.tanh(logsd) * rescale + scale_shift

    pz = gaussian_diag(mean, logsd)
    logp = lambda z1: pz.logp(z1)
    eps = lambda z1: pz.get_eps(z1)
    sample = lambda eps: pz.sample(eps)

    return logp, sample, eps
コード例 #4
0
ファイル: models.py プロジェクト: omidsakhi/tpu_glow
def prior(name, y_onehot, cfg):

    with tf.variable_scope(name):

        cfg.top_shape = [1, 1, 768]

        n_z = cfg.top_shape[-1]

        h = tf.zeros([tf.shape(y_onehot)[0]]+cfg.top_shape[:2]+[2*n_z])
        if cfg.learntop:
            assert(False)
            h = ops._conv2d('p', h, 2*n_z, 3, 1, True)
        if cfg.ycond:
            assert(False)
            h += tf.reshape(ops.dense("y_emb", y_onehot, 2*n_z,
                                      True, init_zero=True), [-1, 1, 1, 2 * n_z])

        pz = ops.gaussian_diag(h[:, :, :, :n_z], h[:, :, :, n_z:])

    def logp(z1):
        objective = pz.logp(z1)
        return objective

    def sample(eps=None, eps_std=None, temp=1.0):
        if eps is not None:
            # Already sampled eps. Don't use eps_std
            z = pz.sample_eps(eps)
        elif eps_std is not None:
            # Sample with given eps_std
            z = pz.sample_eps(pz.eps * tf.reshape(eps_std, [-1, 1, 1, 1]))
        else:
            # Sample normally
            z = pz.sample(temp)

        return z

    def eps(z1):
        return pz.get_eps(z1)

    return logp, sample, eps
コード例 #5
0
ファイル: layers.py プロジェクト: winwinJJiang/DLF
def prior(y_onehot, hps, name=None):
    n_z = hps.top_shape[-1]

    h = tf.zeros([tf.shape(y_onehot)[0]] + hps.top_shape[:2] + [2 * n_z])
    h = conv2d_zeros(h, 2 * n_z, name="p")
    if hps.ycond:
        h += tf.reshape(linear_zeros(y_onehot, 2 * n_z, name="y_emb"),
                        [-1, 1, 1, 2 * n_z])
    mean, logsd = tf.split(h, 2, axis=-1)

    rescale = tf.get_variable("rescale", [],
                              initializer=tf.constant_initializer(1.))
    scale_shift = tf.get_variable("scale_shift", [],
                                  initializer=tf.constant_initializer(0.))
    logsd = tf.tanh(logsd) * rescale + scale_shift

    pz = gaussian_diag(mean, logsd)
    logp = lambda z1: pz.logp(z1)
    eps = lambda z1: pz.get_eps(z1)
    sample = lambda eps: pz.sample(eps)

    return logp, sample, eps
コード例 #6
0
ファイル: models.py プロジェクト: omidsakhi/tpu_glow
def split2d_prior(z, cfg):
    n_z = int(z.get_shape()[3])
    h = f_('split2d_prior', z, cfg, n_out=n_z * 2)
    mean = h[:, :, :, 0::2]
    logs = h[:, :, :, 1::2]
    return ops.gaussian_diag(mean, logs)