Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 3
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
Exemplo n.º 4
0
    def __call__(self, x, is_train=True):
        with tf.variable_scope(self.name, reuse=self._reuse):
            # 14 14 128
            C = self.block('block1', x, self._nf, is_train, False)
            # 7 7 256
            C = self.block('block2', C, self._nf * 2, is_train)
            # 4 4 512
            C = Cn = self.block('block3', C, self._nf * 4, is_train)
            # 4*4*512
            C = tf.reshape(C, [self._batch_size, -1])
            # 10
            C = ops.linear(C, self._num_labels, 'linear')

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

            return C, Cn
Exemplo n.º 5
0
    def __call__(self, x, is_train=True):
        with tf.variable_scope(self.name, reuse=self._reuse):
            # 128 128 64 -> 64 64 128
            D = self.block('block1', x, self._nf)
            # 64 64 128 -> 32 32 256
            D = self.block('block2', D, self._nf * 2)
            # 32 32 256 -> 16 16 512
            D = self.block('block3', D, self._nf * 4)
            # 16 16 512
            D = Cn = self.block('block4', D, self._nf * 8, True)
            # 512 / GAP
            D = tf.reduce_mean(D, axis=[1, 2])
            # 1
            D = ops.linear(D, 1, 'linear', use_sn=self._sn)

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

            return D, Cn
Exemplo n.º 6
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