Beispiel #1
0
    def generator(self, x, reuse=None):
        with tf.variable_scope('generator', reuse=reuse):

            def residual_block(x, f, name=""):
                with tf.variable_scope(name, reuse=reuse):
                    skip_connection = tf.identity(x,
                                                  name='gen-skip_connection-1')

                    x = t.conv2d(x, f, 3, 1, name='gen-conv2d-1')
                    x = t.instance_norm(x, reuse=reuse, name='gen-inst_norm-1')
                    x = tf.nn.relu(x)
                    x = t.conv2d(x, f, 3, 1, name='gen-conv2d-2')
                    x = tf.nn.relu(x)

                    return skip_connection + x

            shortcut = tf.identity(x, name='shortcut-init')

            x = t.conv2d(x, self.gf_dim * 1, 7, 1, name='gen-conv2d-1')
            x = t.instance_norm(x,
                                affine=False,
                                reuse=reuse,
                                name='gen-inst_norm-1')
            x = tf.nn.relu(x)

            for i in range(1, 3):
                x = t.conv2d(x,
                             self.gf_dim * (2**i),
                             3,
                             2,
                             name='gen-conv2d-%d' % (i + 1))
                x = t.instance_norm(x,
                                    affine=False,
                                    reuse=reuse,
                                    name='gen-inst_norm-%d' % (i + 1))
                x = tf.nn.relu(x)

            # 9 Residual Blocks
            for i in range(9):
                x = residual_block(x,
                                   self.gf_dim * 4,
                                   name='gen-residual_block-%d' % (i + 1))

            for i in range(1, 3):
                x = t.deconv2d(x,
                               self.gf_dim * (2**i),
                               3,
                               2,
                               name='gen-deconv2d-%d' % i)
                x = t.instance_norm(x,
                                    affine=False,
                                    reuse=reuse,
                                    name='gen-inst_norm-%d' % (i + 3))
                x = tf.nn.relu(x)

            x = t.conv2d(x, self.gf_dim * 1, 7, 1, name='gen-conv2d-4')
            x = tf.nn.tanh(x)
            return shortcut + x
Beispiel #2
0
def residual_block(x, f, name="0"):
    with tf.variable_scope("residual_block-" + name):
        scope_name = "residual_block-" + name

        x = t.conv2d(x, f=f, k=3, s=1)
        x = t.instance_norm(x, affine=True, name=scope_name + '_0')
        x = tf.nn.relu(x)

        x = t.conv2d(x, f=f, k=3, s=1)
        x = t.instance_norm(x, affine=True, name=scope_name + '_1')

        return x
Beispiel #3
0
            def conv_in_relu(x, f, k, s, de=False, name=""):
                if not de:
                    x = t.conv2d(x, f=f, k=k, s=s)
                else:
                    x = t.deconv2d(x, f=f, k=k, s=s)

                x = t.instance_norm(x, name=name)
                x = tf.nn.relu(x)
                return x
 def u(x, f, name=''):
     x = t.deconv2d(x,
                    f=f,
                    k=3,
                    s=2,
                    name='gen-u-deconv2d-%s' % name)
     x = t.instance_norm(x, name='gen-u-ins_norm-%s' % name)
     x = tf.nn.relu(x)
     return x
Beispiel #5
0
            def residual_block(x, f, name=""):
                with tf.variable_scope(name, reuse=reuse):
                    skip_connection = tf.identity(x,
                                                  name='gen-skip_connection-1')

                    x = t.conv2d(x, f, 3, 1, name='gen-conv2d-1')
                    x = t.instance_norm(x, reuse=reuse, name='gen-inst_norm-1')
                    x = tf.nn.relu(x)
                    x = t.conv2d(x, f, 3, 1, name='gen-conv2d-2')
                    x = tf.nn.relu(x)

                    return skip_connection + x
Beispiel #6
0
    def discriminator(self, x, reuse=None):
        with tf.variable_scope('discriminator', reuse=reuse):
            x = t.conv2d(x, self.df_dim * 1, 4, 2, name='disc-conv2d-1')
            x = tf.nn.leaky_relu(x)

            for i in range(1, 3):
                x = t.conv2d(x,
                             self.df_dim * (2**i),
                             4,
                             2,
                             name='disc-conv2d-%d' % (i + 1))
                x = t.instance_norm(x,
                                    reuse=reuse,
                                    name='disc-inst_norm-%d' % i)
                x = tf.nn.leaky_relu(x)

            x = t.conv2d(x, self.df_dim * 8, 4, 1, name='disc-conv2d-4')
            x = t.instance_norm(x, reuse=reuse, name='disc-inst_norm-3')
            x = tf.nn.leaky_relu(x)

            x = t.conv2d(x, 1, 4, 1, name='disc-conv2d-5')

            return x
 def R(x, f, name=''):
     x = t.conv2d(x, f=f, k=3, s=1, name='gen-R-conv2d-%s-0' % name)
     x = t.conv2d(x, f=f, k=3, s=1, name='gen-R-conv2d-%s-1' % name)
     x = t.instance_norm(x, name='gen-R-ins_norm-%s' % name)
     x = tf.nn.relu(x)
     return x
 def residual_block(x, f, name=''):
     x = t.conv2d(x, f=f, k=4, s=2, name='disc-conv2d-%s' % name)
     x = t.instance_norm(x, name='disc-ins_norm-%s' % name)
     x = tf.nn.leaky_relu(x, alpha=0.2)
     return x