Ejemplo n.º 1
0
def encoder(x, y, phase, scope='enc', reuse=None, internal_update=False):
    with tf.variable_scope(scope, reuse=reuse):
        with arg_scope([conv2d, dense], bn=True, phase=phase, activation=leaky_relu), \
             arg_scope([batch_norm], internal_update=internal_update):

            # Ignore y
            x = conv2d(x, 64, 3, 2)
            x = conv2d(x, 128, 3, 2)
            x = conv2d(x, 256, 3, 2)
            x = dense(x, 1024)

            # Autoregression (4 steps)
            ms = []
            vs = []
            zs = [x]

            for i in xrange(5):
                h = tf.concat(zs, axis=-1)
                h = dense(h, 100)
                m = dense(h, 20, activation=None)
                v = dense(h, 20, activation=tf.nn.softplus) + 1e-5
                z = gaussian_sample(m, v)
                ms += [m]
                vs += [v]
                zs += [z]

            m = tf.concat(ms, 1)
            v = tf.concat(vs, 1)
            z = tf.concat(zs[1:], 1)

    return z, (m, v)
def encoder(x, phase, reuse=None):
    with tf.variable_scope('enc', reuse=reuse):
        with arg_scope([dense], bn=True, phase=phase, activation=leaky_relu), \
             arg_scope([conv2d], bn=True, phase=phase, activation=leaky_relu):

            if x._shape_as_list()[-1] == 1:
                x = tf.image.grayscale_to_rgb(x)

            x = conv2d(x, 64, 3, 2)
            x = conv2d(x, 128, 3, 2)
            x = conv2d(x, 256, 3, 2)
            x = dense(x, 128)

    return x
Ejemplo n.º 3
0
def classifier(x, phase, reuse=None):
    with tf.variable_scope('class', reuse=reuse):
        with arg_scope([conv2d, dense],
                       bn=True,
                       phase=phase,
                       activation=tf.nn.relu):
            for i in range(4):
                x = conv2d(x, 64 + 64 * i, 3, 2)
                x = conv2d(x, 64 + 64 * i, 3, 1)

            x = dense(x, 500)
            x = dense(x, 10, activation=None)

    return x
def encoder(x, y, phase, reuse=None):
    with tf.variable_scope('enc', reuse=reuse):
        with arg_scope([conv2d, dense], bn=True, phase=phase, activation=leaky_relu), \
             arg_scope([noise], phase=phase):

            # Ignore y
            x = conv2d(x, 64, 3, 2, bn=False)
            x = conv2d(x, 128, 3, 2)
            x = conv2d(x, 256, 3, 2)
            x = dense(x, 1024)

            m = dense(x, 100, activation=None)
            v = dense(x, 100, activation=tf.nn.softplus) + 1e-5

            return (m, v)
Ejemplo n.º 5
0
def discriminator(x, phase, reuse=None, depth=1):
    with tf.variable_scope('disc', reuse=reuse):
        with arg_scope([conv2d, dense], bn=True, phase=phase, activation=lrelu), \
             arg_scope([noise], phase=phase):

            x = dropout(x, rate=0.2, training=phase)
            x = conv2d(x, 64, 3, 2, bn=False)
            x = dropout(x, training=phase)
            x = conv2d(x, 128, 3, 2)
            x = dropout(x, training=phase)
            x = conv2d(x, 256, 3, 2)
            x = dropout(x, training=phase)
            x = dense(x, 1024)
            x = dense(x, depth, activation=None, bn=False)
    return x
Ejemplo n.º 6
0
def encoder(x, y, phase, scope='enc', reuse=None, internal_update=False):
    with tf.variable_scope(scope, reuse=reuse):
        with arg_scope([conv2d, dense], bn=True, phase=phase, activation=leaky_relu), \
             arg_scope([batch_norm], internal_update=internal_update):

            # Ignore y
            x = conv2d(x, 64, 3, 2)
            x = conv2d(x, 128, 3, 2)
            x = conv2d(x, 256, 3, 2)
            x = dense(x, 1024)

            m = dense(x, 100, activation=None)
            v = dense(x, 100, activation=tf.nn.softplus) + 1e-5
            z = gaussian_sample(m, v)

            return z, (m, v)
Ejemplo n.º 7
0
def encoder(x, phase, reuse=None):
    with tf.variable_scope('enc', reuse=reuse):
        with arg_scope([dense], bn=True, phase=phase, activation=leaky_relu), \
             arg_scope([conv2d], bn=True, phase=phase, activation=leaky_relu):

            if x._shape_as_list()[-1] == 1:
                x = tf.image.grayscale_to_rgb(x)

            if args.dense:
                # Level 0: 32
                l0 = x

                # Level 1: 32 -> 16, 8, 4
                a1 = conv2d(l0, 64, 3, 2)
                a2 = conv2d(l0, 64, 5, 4)
                a3 = conv2d(l0, 64, 9, 8)
                l1 = a1

                # Level 2: 16 -> 8, 4
                b2 = conv2d(l1, 64, 3, 2)
                b3 = conv2d(l1, 64, 5, 4)
                l2 = tf.concat([a2, b2], -1)

                # Level 3: 8 -> 4
                c3 = conv2d(l2, 64, 3, 2)
                l3 = tf.concat([a3, b3, c3], -1)

                # Level 4: Dense
                x = dense(l3, 128)

            else:
                x = conv2d(x, 64, 3, 2)
                x = conv2d(x, 128, 3, 2)
                x = conv2d(x, 256, 3, 2)
                x = dense(x, 128)

    return x