Beispiel #1
0
    def block(self, name, x, chout, spout, is_train, is_last=False):
        with tf.variable_scope(name, reuse=self._reuse):
            if not is_last:
                G = ops.deconv2d(x, [self._batch_size, spout, spout, chout],
                                 4,
                                 4,
                                 2,
                                 2,
                                 name='conv',
                                 use_sn=self._sn,
                                 xavier=True)
                G = ops.norms(G, is_train, 'norm', self._norm)
                G = ops.acts(G, self._activation)
            else:
                G = ops.deconv2d(x, [self._batch_size, spout, spout, chout],
                                 3,
                                 3,
                                 1,
                                 1,
                                 name='conv',
                                 use_sn=self._sn,
                                 xavier=True)
                G = ops.acts(G, 'tanh')

            return G
Beispiel #2
0
    def block(self, name, x, chout, is_train, is_last=False, is_first=False):
        with tf.variable_scope(name, reuse=self._reuse):
            D = ops.conv2d(x,
                           chout,
                           3,
                           3,
                           1,
                           1,
                           0.02,
                           'conv1',
                           use_sn=self._sn,
                           xavier=True)
            if not is_first:
                D = ops.norms(D, is_train, 'norm1', self._norm)
            D = ops.acts(D, self._activation)

            if not is_last:
                D = ops.conv2d(D,
                               chout * 2,
                               4,
                               4,
                               2,
                               2,
                               0.02,
                               'conv2',
                               use_sn=self._sn,
                               xavier=True)
                if not is_first:
                    D = ops.norms(D, is_train, 'norm2', self._norm)
                D = ops.acts(D, self._activation)

            return D
Beispiel #3
0
 def FCblock(self, name, x, chout, is_train, is_last=False):
     with tf.variable_scope(name, reuse=self._reuse):
         C = ops.linear(x, chout, 'linear')
         if not is_last:
             C = ops.norms(C, is_train, 'norm', self._norm)
             C = ops.acts(C, self._activation)
         return C
Beispiel #4
0
    def __call__(self, z, y=None, is_train=True):
        with tf.variable_scope(self.name, reuse=self._reuse):
            if y is not None:
                z = tf.concat([z, y], 1)
                y = tf.reshape(y, [self._batch_size, 1, 1, y.shape[-1].value])
            # 16*16*512
            G = ops.linear(z,
                           16 * 16 * self._nf * 8,
                           'linear1',
                           use_sn=self._sn)
            # 16*16*512
            G = tf.reshape(G, [-1, 16, 16, self._nf * 8])
            G = ops.norms(G, is_train, 'norm1', self._norm)
            G = ops.acts(G, self._activation)
            # 32 32 256
            if y is not None:
                G = ops.conv_cond_concat(G, y)
            G = self.block('block1', G, self._nf * 4, 32, is_train)
            # 64 64 128
            if y is not None:
                G = ops.conv_cond_concat(G, y)
            G = self.block('block2', G, self._nf * 2, 64, is_train)
            # 128 128 64
            if y is not None:
                G = ops.conv_cond_concat(G, y)
            G = self.block('block3', G, self._nf, 128, is_train)
            # 128 128 3
            G = self.block('block4', G, 3, 128, is_train, True)

            self._reuse = True
            self.var_list = tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES,
                                              self.name)
            return G
Beispiel #5
0
 def convblock(self, name, x, chout, is_train, is_last=False, s=2):
     with tf.variable_scope(name, reuse=self._reuse):
         Cn = ops.conv2d(x, chout, 4, 4, s, s, xavier=True)
         if not is_last:
             Cn = ops.norms(Cn, is_train, 'norm', self._norm)
             Cn = ops.acts(Cn, self._activation)
         return Cn
Beispiel #6
0
    def block(self, name, x, chout, is_train, is_norm=True, is_act=True):
        with tf.variable_scope(name, reuse=self._reuse):
            M = ops.linear(x, chout, 'linear')
            if is_norm:
                M = ops.norms(M, is_train, 'norm', self._norm)
            if is_act:
                M = ops.acts(M, self._activation)

            return M
Beispiel #7
0
    def block(self, name, x, chout, is_train, use_norm=True):
        with tf.variable_scope(name, reuse=self._reuse):
            C = ops.conv2d(x,
                           chout,
                           5,
                           5,
                           2,
                           2,
                           0.02,
                           'conv',
                           use_sn=self._sn,
                           xavier=True)
            if use_norm:
                C = ops.norms(C, is_train, 'norm', self._norm)
            C = ops.acts(C, self._activation)

            return C
Beispiel #8
0
    def __call__(self, z, y=None, is_train=True):
        with tf.variable_scope(self.name, reuse=self._reuse):
            if y is not None:
                z = tf.concat([z, y], 1)
            # 4*4*512
            G = ops.linear(z, 4 * 4 * self._nf * 4, 'linear')
            # 4 4 512
            G = tf.reshape(G, [-1, 4, 4, self._nf * 4])
            G = ops.norms(G, is_train, 'norm', self._norm)
            G = ops.acts(G, self._activation)
            # 7 7 256
            G = self.block('block1', G, self._nf * 2, 7, is_train)
            # 14 14 128
            G = self.block('block2', G, self._nf, 14, is_train)
            # 28 28 1
            G = self.block('block3', G, 1, 28, is_train, True)

            self._reuse = True
            self.var_list = tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES,
                                              self.name)
            return G