Exemple #1
0
    def discriminator(self, inp, cond, stages, t, reuse=False):
        alpha_trans = self.alpha_tra
        with tf.variable_scope("d_net", reuse=reuse):
            x_iden = None
            if t:
                x_iden = pool(inp, 2)
                x_iden = self.from_rgb(x_iden, stages - 2)

            x = self.from_rgb(inp, stages - 1)

            for i in range(stages - 1, 0, -1):
                with tf.variable_scope(self.get_conv_scope_name(i), reuse=reuse):
                    x = conv2d(x, f=self.get_dnf(i), ks=(3, 3), s=(1, 1), act=lrelu_act())
                    x = conv2d(x, f=self.get_dnf(i-1), ks=(3, 3), s=(1, 1), act=lrelu_act())
                    x = pool(x, 2)
                if i == stages - 1 and t:
                    x = tf.multiply(alpha_trans, x) + tf.multiply(tf.subtract(1., alpha_trans), x_iden)

            with tf.variable_scope(self.get_conv_scope_name(0), reuse=reuse):
                # Real/False branch
                cond_compress = fc(cond, units=128, act=lrelu_act())
                concat = self.concat_cond4(x, cond_compress)
                x_b1 = conv2d(concat, f=self.get_dnf(0), ks=(3, 3), s=(1, 1), act=lrelu_act())
                x_b1 = conv2d(x_b1, f=self.get_dnf(0), ks=(4, 4), s=(1, 1), padding='VALID', act=lrelu_act())
                output_b1 = fc(x_b1, units=1)

            return output_b1
 def build_down_block(self, inputs, name, down_outputs, first=False):
     out_num = self.conf.start_channel_num if first else 2 * \
         inputs.shape[self.channel_axis].value
     conv1 = ops.conv(inputs, out_num, self.conv_size, name + '/conv1',
                      self.conf.data_type)
     conv2 = ops.conv(conv1, out_num, self.conv_size, name + '/conv2',
                      self.conf.data_type)
     down_outputs.append(conv2)
     pool = ops.pool(conv2, self.pool_size, name + '/pool',
                     self.conf.data_type)
     return pool