예제 #1
0
    def __call__(self, D_input):
        """
        Args:
          input: batch_size x image_size x image_size x 3
        Returns:
          output: 4D tensor batch_size x out_size x out_size x 1 (default 1x5x5x1)
                  filled with 0.9 if real, 0.0 if fake
        """

        with tf.variable_scope(self.name, reuse=self.reuse):
            D_input = tf.nn.dropout(D_input, keep_prob=self.keep_prob)
            with tf.variable_scope("conv0", reuse=self.reuse):
                conv0 = tf.layers.conv2d(
                    inputs=D_input,
                    filters=2 * self.ngf,
                    kernel_size=5,
                    strides=self.slice_stride,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=0.0, stddev=0.02, dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv0')
                norm0 = ops._norm(conv0, self.is_training, self.norm)
                relu0 = ops.relu(norm0)
            with tf.variable_scope("conv1", reuse=self.reuse):
                conv1 = tf.layers.conv2d(
                    inputs=relu0,
                    filters=4 * self.ngf,
                    kernel_size=3,
                    strides=self.slice_stride,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=0.0, stddev=0.02, dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv1')
                norm1 = ops._norm(conv1, self.is_training, self.norm)
                relu1 = ops.relu(norm1)
            with tf.variable_scope("conv2", reuse=self.reuse):
                conv2 = tf.layers.conv2d(
                    inputs=relu1,
                    filters=8 * self.ngf,
                    kernel_size=3,
                    strides=self.slice_stride,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=0.0, stddev=0.02, dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv2')
                norm2 = ops._norm(conv2, self.is_training, self.norm)
                relu2 = ops.relu(norm2)
            with tf.variable_scope("conv3", reuse=self.reuse):
                conv3 = tf.layers.conv2d(
                    inputs=relu2,
                    filters=8 * self.ngf,
                    kernel_size=3,
                    strides=self.slice_stride,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=0.0, stddev=0.02, dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv3')
                norm3 = ops._norm(conv3, self.is_training, self.norm)
                relu3 = ops.relu(norm3)
            with tf.variable_scope("conv4", reuse=self.reuse):
                conv4 = tf.layers.conv2d(
                    inputs=relu3,
                    filters=4 * self.ngf,
                    kernel_size=3,
                    strides=self.slice_stride,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=0.0, stddev=0.02, dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv4')
                norm4 = ops._norm(conv4, self.is_training, self.norm)
                relu4 = ops.relu(norm4)
            with tf.variable_scope("conv5", reuse=self.reuse):
                output = tf.layers.conv2d(
                    inputs=relu4,
                    filters=1,
                    kernel_size=3,
                    strides=self.slice_stride,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=0.0, stddev=0.02, dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv5')

        self.reuse = True
        self.variables = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES,
                                           scope=self.name)

        return output
예제 #2
0
    def __call__(self, EC_input):
        """
        Args:
          input: batch_size x width x height x 3
        Returns:
          output: same size as input
        """

        with tf.variable_scope(self.name):
            EC_input = tf.nn.dropout(EC_input, keep_prob=self.keep_prob)
            with tf.variable_scope("conv0", reuse=self.reuse):
                conv0 = tf.layers.conv2d(
                    inputs=EC_input,
                    filters=self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / 9.0, stddev=0.000001, dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv0')
                norm0 = ops.norm(conv0)
                relu0 = ops.relu(norm0)
            # pool1
            with tf.variable_scope("conv1", reuse=self.reuse):
                conv1 = tf.layers.conv2d(
                    inputs=relu0,
                    filters=2 * self.ngf,
                    kernel_size=3,
                    strides=2,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv1')
                norm1 = ops._norm(conv1)
                relu1 = ops.relu(norm1)
            # w/2,h/2
            with tf.variable_scope("conv2", reuse=self.reuse):
                conv2 = tf.layers.conv2d(
                    inputs=relu1,
                    filters=2 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 2 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv2')
                norm2 = ops._norm(conv2)
                relu2 = ops.relu(norm2)
            # pool2
            with tf.variable_scope("conv3", reuse=self.reuse):
                conv3 = tf.layers.conv2d(
                    inputs=relu2,
                    filters=4 * self.ngf,
                    kernel_size=3,
                    strides=2,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 2 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv3')
                norm3 = ops._norm(conv3)
                relu3 = ops.relu(norm3)
            # w/4,h/4
            with tf.variable_scope("conv4", reuse=self.reuse):
                conv4 = tf.layers.conv2d(
                    inputs=relu3,
                    filters=4 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 4 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv4')
                norm4 = ops._norm(conv4)
                relu4 = ops.relu(norm4)
            with tf.variable_scope("conv5", reuse=self.reuse):
                conv5 = tf.layers.conv2d(
                    inputs=relu4,
                    filters=4 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 4 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv5')
                norm5 = ops._norm(conv5)
                relu5 = tf.nn.relu(norm5)
            # pool3
            with tf.variable_scope("conv6", reuse=self.reuse):
                conv6 = tf.layers.conv2d(
                    inputs=relu5,
                    filters=6 * self.ngf,
                    kernel_size=3,
                    strides=2,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 4 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv6')
                norm6 = ops._norm(conv6)
                relu6 = ops.relu(norm6)
            # w/8,h/8 18 23
            with tf.variable_scope("conv7", reuse=self.reuse):
                conv7 = tf.layers.conv2d(
                    inputs=relu6,
                    filters=6 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 6 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv7')
                norm7 = ops._norm(conv7)
                relu7 = ops.relu(norm7)
            # pool4
            with tf.variable_scope("conv8", reuse=self.reuse):
                conv8 = tf.layers.conv2d(
                    inputs=relu7,
                    filters=8 * self.ngf,
                    kernel_size=3,
                    strides=2,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 6 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv8')
                norm8 = ops._norm(conv8)
                relu8 = tf.nn.relu(norm8)
            # 9 12
            with tf.variable_scope("conv9", reuse=self.reuse):
                conv9 = tf.layers.conv2d(
                    inputs=relu8,
                    filters=8 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 8 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv9')
                norm9 = ops._norm(conv9)
                relu9 = tf.nn.relu(norm9)
            # pool5
            with tf.variable_scope("conv10", reuse=self.reuse):
                conv10 = tf.layers.conv2d(
                    inputs=relu9,
                    filters=12 * self.ngf,
                    kernel_size=3,
                    strides=2,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 8 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv10')
                norm10 = ops._norm(conv10)
                relu10 = tf.nn.relu(norm10)
                conv_output = tf.layers.flatten(relu10)
            # 5 6
            with tf.variable_scope("dense1", reuse=self.reuse):
                mean = tf.layers.dense(conv_output, units=4096, name="dense1")
            with tf.variable_scope("dense2", reuse=self.reuse):
                log_var = tf.layers.dense(conv_output,
                                          units=4096,
                                          name="dense2")

        self.reuse = True
        self.variables = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES,
                                           scope=self.name)
        return mean, log_var
예제 #3
0
    def __call__(self, EC_input):
        """
        Args:
          input: batch_size x width x height x 3
        Returns:
          output: same size as input
        """

        with tf.variable_scope(self.name):
            EC_input = tf.nn.dropout(EC_input, keep_prob=self.keep_prob)
            with tf.variable_scope("conv1", reuse=self.reuse):
                conv1 = tf.layers.conv2d(
                    inputs=EC_input,
                    filters=self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 1),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv1')
                norm1 = ops._norm(conv1, self.is_training, self.norm)
                relu1 = ops.relu(norm1)
            with tf.variable_scope("conv2", reuse=self.reuse):
                conv2 = tf.layers.conv2d(
                    inputs=relu1,
                    filters=self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv2')
                norm2 = ops._norm(conv2, self.is_training, self.norm)
                relu2 = ops.relu(norm2)
            # pool1
            with tf.variable_scope("conv3", reuse=self.reuse):
                conv3 = tf.layers.conv2d(
                    inputs=relu2,
                    filters=self.ngf,
                    kernel_size=3,
                    strides=self.slice_stride,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv3')
                # norm3 = ops._norm(conv3, self.is_training, self.norm)
                # relu3 = ops.relu(norm3)
            with tf.variable_scope("conv4", reuse=self.reuse):
                conv4 = tf.layers.conv2d(
                    inputs=conv3,
                    filters=2 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv4')
                norm4 = ops._norm(conv4, self.is_training, self.norm)
                relu4 = ops.relu(norm4)
            with tf.variable_scope("conv5", reuse=self.reuse):
                conv5 = tf.layers.conv2d(
                    inputs=relu4,
                    filters=2 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 2 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv5')
                norm5 = ops._norm(conv5, self.is_training, self.norm)
                relu5 = tf.nn.relu(norm5)
            # pool2
            with tf.variable_scope("conv6", reuse=self.reuse):
                conv6 = tf.layers.conv2d(
                    inputs=relu5,
                    filters=2 * self.ngf,
                    kernel_size=3,
                    strides=self.slice_stride,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 2 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv6')
                # norm6 = ops._norm(conv6, self.is_training, self.norm)
                # relu6 = ops.relu(norm6)
            with tf.variable_scope("conv7", reuse=self.reuse):
                conv7 = tf.layers.conv2d(
                    inputs=conv6,
                    filters=4 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 2 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv7')
                norm7 = ops._norm(conv7, self.is_training, self.norm)
                relu7 = ops.relu(norm7)
            with tf.variable_scope("conv8", reuse=self.reuse):
                conv8 = tf.layers.conv2d(
                    inputs=relu7,
                    filters=4 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 4 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv8')
                norm8 = ops._norm(conv8, self.is_training, self.norm)
                relu8 = ops.relu(norm8)
            # pool3
            with tf.variable_scope("conv9", reuse=self.reuse):
                conv9 = tf.layers.conv2d(
                    inputs=relu8,
                    filters=4 * self.ngf,
                    kernel_size=3,
                    strides=self.slice_stride,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 4 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv9')
            # DC
            with tf.variable_scope("conv10", reuse=self.reuse):
                conv10 = tf.layers.conv2d(
                    inputs=conv9,
                    filters=4 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 4 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv10')
                norm10 = ops._norm(conv10, self.is_training, self.norm)
                relu10 = ops.relu(norm10)
            with tf.variable_scope("deconv1_r", reuse=self.reuse):
                resize1 = ops.uk_resize(relu10,
                                        reuse=self.reuse,
                                        name='resize1')
                deconv1_r = tf.layers.conv2d(
                    inputs=resize1,
                    filters=4 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 4 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='deconv1_r')
                deconv1_norm1_r = ops._norm(deconv1_r, self.is_training,
                                            self.norm)
                deconv1 = ops.relu(deconv1_norm1_r)
            with tf.variable_scope("concat1", reuse=self.reuse):
                concat1 = tf.concat([relu8, deconv1], axis=-1)
            with tf.variable_scope("add1_conv1", reuse=self.reuse):
                add1_conv1 = tf.layers.conv2d(
                    inputs=concat1,
                    filters=2 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 8 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='add1_conv1')
                add1_norm1 = ops._norm(add1_conv1, self.is_training, self.norm)
                add1_relu1 = ops.relu(add1_norm1)
            with tf.variable_scope("add1_conv2", reuse=self.reuse):
                add1_conv2 = tf.layers.conv2d(
                    inputs=add1_relu1,
                    filters=2 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 2 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='add1_conv2')
                add1_norm2 = ops._norm(add1_conv2, self.is_training, self.norm)
                add1_relu2 = ops.relu(add1_norm2)
            with tf.variable_scope("deconv2_r", reuse=self.reuse):
                resize2 = ops.uk_resize(add1_relu2,
                                        reuse=self.reuse,
                                        name='resize2')
                deconv2_r = tf.layers.conv2d(
                    inputs=resize2,
                    filters=2 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 2 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='deconv2_r')
                deconv2_norm1_r = ops._norm(deconv2_r, self.is_training,
                                            self.norm)
                deconv2 = ops.relu(deconv2_norm1_r)
            with tf.variable_scope("concat2", reuse=self.reuse):
                concat2 = tf.concat([relu5, deconv2], axis=-1)
            with tf.variable_scope("add2_conv1", reuse=self.reuse):
                add2_conv1 = tf.layers.conv2d(
                    inputs=concat2,
                    filters=self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 4 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='add2_conv1')
                add2_norm1 = ops._norm(add2_conv1, self.is_training, self.norm)
                add2_relu1 = ops.relu(add2_norm1)
            with tf.variable_scope("add2_conv2", reuse=self.reuse):
                add2_conv = tf.layers.conv2d(
                    inputs=add2_relu1,
                    filters=self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='add2_conv2')
                add2_norm2 = ops._norm(add2_conv, self.is_training, self.norm)
                add2_relu2 = ops.relu(add2_norm2)
            with tf.variable_scope("deconv3_r", reuse=self.reuse):
                resize3 = ops.uk_resize(add2_relu2,
                                        reuse=self.reuse,
                                        name='resize3')
                deconv3_r = tf.layers.conv2d(
                    inputs=resize3,
                    filters=self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='deconv3_r')
                deconv3_norm1_r = ops._norm(deconv3_r, self.is_training,
                                            self.norm)
                deconv3 = ops.relu(deconv3_norm1_r)
            with tf.variable_scope("concat2", reuse=self.reuse):
                concat3 = tf.concat([relu2, deconv3], axis=-1)
            with tf.variable_scope("add3_conv1", reuse=self.reuse):
                add3_conv1 = tf.layers.conv2d(
                    inputs=concat3,
                    filters=self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 2 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='add3_conv1')
                add3_norm1 = ops._norm(add3_conv1, self.is_training, self.norm)
                add3_relu1 = ops.relu(add3_norm1)
            with tf.variable_scope("add3_conv2", reuse=self.reuse):
                add3_conv2 = tf.layers.conv2d(
                    inputs=add3_relu1,
                    filters=self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='add3_conv2')
                add3_norm2 = ops._norm(add3_conv2, self.is_training, self.norm)
                add3_relu2 = ops.relu(add3_norm2)
            with tf.variable_scope("lastconv", reuse=self.reuse):
                lastconv = tf.layers.conv2d(
                    inputs=add3_relu2,
                    filters=self.output_channl,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='lastconv')
                lastnorm = ops._norm(lastconv, self.is_training, self.norm)
                output = tf.nn.sigmoid(lastnorm)
        self.reuse = True
        self.variables = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES,
                                           scope=self.name)
        return output
    def __call__(self, DC_input):
        """
        Args:
          input: batch_size x width x height x N
        Returns:
          output: same size as input
        """
        with tf.variable_scope(self.name, reuse=self.reuse):
            with tf.variable_scope("dense0", reuse=self.reuse):
                dense0 = tf.layers.dense(
                    DC_input,
                    units=DC_input.get_shape().as_list()[0] * 6 * 5 * self.ngf,
                    name="dense0")
            with tf.variable_scope("dense1", reuse=self.reuse):
                dense1 = tf.layers.dense(
                    dense0,
                    units=DC_input.get_shape().as_list()[0] * 6 * 5 * 12 *
                    self.ngf,
                    name="dense0")
                dense1 = tf.reshape(dense1,
                                    shape=[
                                        DC_input.get_shape().as_list()[0], 6,
                                        5, 12 * self.ngf
                                    ])
            # 6,5
            with tf.variable_scope("conv0_1", reuse=self.reuse):
                conv0_1 = tf.layers.conv2d(
                    inputs=dense1,
                    filters=12 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 12 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv0_1')
                norm0_1 = ops._norm(conv0_1, self.is_training, self.norm)
                relu0_1 = ops.relu(norm0_1)
            # 6,5
            with tf.variable_scope("deconv0_1_r", reuse=self.reuse):
                resize0_1 = ops.uk_resize(relu0_1,
                                          reuse=self.reuse,
                                          output_size=[12, 9],
                                          name='resize')
                deconv0_1_r = tf.layers.conv2d(
                    inputs=resize0_1,
                    filters=8 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 12 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='deconv0_1_r')
                deconv0_1_norm1_r = ops._norm(deconv0_1_r, self.is_training,
                                              self.norm)
                deconv0_1_relu1 = ops.relu(deconv0_1_norm1_r)
            # 12,9
            with tf.variable_scope("conv0_2", reuse=self.reuse):
                conv0_2 = tf.layers.conv2d(
                    inputs=deconv0_1_relu1,
                    filters=8 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 8 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv0_2')
                norm0_2 = ops._norm(conv0_2, self.is_training, self.norm)
                relu0_2 = ops.relu(norm0_2)
            # 12,9
            with tf.variable_scope("deconv0_2_r", reuse=self.reuse):
                resize0_2 = ops.uk_resize(relu0_2,
                                          reuse=self.reuse,
                                          output_size=[23, 18],
                                          name='resize')
                deconv0_2_r = tf.layers.conv2d(
                    inputs=resize0_2,
                    filters=6 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 8 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='deconv0_2_r')
                deconv0_2_norm1_r = ops._norm(deconv0_2_r, self.is_training,
                                              self.norm)
                deconv0_2_relu1 = ops.relu(deconv0_2_norm1_r)
            # 23, 18
            with tf.variable_scope("conv0_3", reuse=self.reuse):
                conv0_3 = tf.layers.conv2d(
                    inputs=deconv0_2_relu1,
                    filters=6 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 6 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv0_3')
                norm0_3 = ops._norm(conv0_3, self.is_training, self.norm)
                relu0_3 = ops.relu(norm0_3)
            # 23, 18
            with tf.variable_scope("deconv0_3_r", reuse=self.reuse):
                resize0_3 = ops.uk_resize(relu0_3,
                                          reuse=self.reuse,
                                          name='resize')
                deconv0_3_r = tf.layers.conv2d(
                    inputs=resize0_3,
                    filters=6 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 6 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='deconv0_3_r')
                deconv0_3_norm1_r = ops._norm(deconv0_3_r, self.is_training,
                                              self.norm)
                add0 = ops.relu(deconv0_3_norm1_r)
            # 46, 36
            with tf.variable_scope("conv1", reuse=self.reuse):
                conv1 = tf.layers.conv2d(
                    inputs=add0,
                    filters=6 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 6 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv1')
                norm1 = ops._norm(conv1, self.is_training, self.norm)
                relu1 = ops.relu(norm1)
            with tf.variable_scope("deconv1_r", reuse=self.reuse):
                resize1 = ops.uk_resize(relu1, reuse=self.reuse, name='resize')
                deconv1_r = tf.layers.conv2d(
                    inputs=resize1,
                    filters=4 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 6 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='deconv1_r')
                deconv1_norm1_r = ops._norm(deconv1_r, self.is_training,
                                            self.norm)
                add1 = ops.relu(deconv1_norm1_r)
            with tf.variable_scope("add1_conv1", reuse=self.reuse):
                add1_conv1 = tf.layers.conv2d(
                    inputs=add1,
                    filters=4 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 4 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='add1_conv1')
                add1_norm1 = ops._norm(add1_conv1, self.is_training, self.norm)
                add1_relu1 = ops.relu(add1_norm1)
            with tf.variable_scope("add1_conv2", reuse=self.reuse):
                add1_conv2 = tf.layers.conv2d(
                    inputs=add1_relu1,
                    filters=4 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 4 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='add1_conv2')
                add1_norm2 = ops._norm(add1_conv2, self.is_training, self.norm)
                add1_relu2 = ops.relu(add1_norm2)
            with tf.variable_scope("deconv2_r", reuse=self.reuse):
                resize2 = ops.uk_resize(add1_relu2,
                                        reuse=self.reuse,
                                        name='resize')
                deconv2_r = tf.layers.conv2d(
                    inputs=resize2,
                    filters=2 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 4 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='deconv2_r')
                deconv2_norm1_r = ops._norm(deconv2_r, self.is_training,
                                            self.norm)
                add2 = ops.relu(deconv2_norm1_r)
            with tf.variable_scope("add2_conv1", reuse=self.reuse):
                add2_conv1 = tf.layers.conv2d(
                    inputs=add2,
                    filters=2 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 2 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='add2_conv1')
                add2_norm1 = ops._norm(add2_conv1, self.is_training, self.norm)
                add2_relu1 = ops.relu(add2_norm1)
            with tf.variable_scope("add2_conv2", reuse=self.reuse):
                add2_conv = tf.layers.conv2d(
                    inputs=add2_relu1,
                    filters=2 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 2 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='add2_conv2')
                add2_norm2 = ops._norm(add2_conv, self.is_training, self.norm)
                add2_relu2 = ops.relu(add2_norm2)
            with tf.variable_scope("conv2", reuse=self.reuse):
                conv2 = tf.layers.conv2d(
                    inputs=add2_relu2,
                    filters=self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 2 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv2')
                norm2 = ops._norm(conv2, self.is_training, self.norm)
                relu2 = ops.relu(norm2)
            with tf.variable_scope("lastconv", reuse=self.reuse):
                lastconv = tf.layers.conv2d(
                    inputs=relu2,
                    filters=self.output_channl,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='lastconv')
                lastnorm = ops._norm(lastconv, self.is_training, self.norm)
                output = tf.nn.sigmoid(lastnorm)

        self.reuse = True
        self.variables = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES,
                                           scope=self.name)
        return output
예제 #5
0
    def __call__(self, D_input):
        """
        Args:
          input: batch_size x image_size x image_size x N
        Returns:
          output_1: 4D tensor batch_size x out_size x out_size x 1
                  filled with 1.0 if real, 0.0 if fake
          output_2: 4D tensor classifier result
        """

        with tf.variable_scope(self.name, reuse=self.reuse):
            D_input = tf.nn.dropout(D_input, keep_prob=self.keep_prob)
            with tf.variable_scope("conv0", reuse=self.reuse):
                conv0 = tf.layers.conv2d(
                    inputs=D_input,
                    filters=self.ngf,
                    kernel_size=5,
                    strides=2,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=0.0, stddev=0.02, dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv0')
                norm0 = ops._norm(conv0)
                relu0 = ops.relu(norm0)
            with tf.variable_scope("conv1", reuse=self.reuse):
                conv1 = tf.layers.conv2d(
                    inputs=relu0,
                    filters=2 * self.ngf,
                    kernel_size=3,
                    strides=2,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=0.0, stddev=0.02, dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv1')
                norm1 = ops._norm(conv1)
                relu1 = ops.relu(norm1)
            with tf.variable_scope("conv2", reuse=self.reuse):
                conv2 = tf.layers.conv2d(
                    inputs=relu1,
                    filters=4 * self.ngf,
                    kernel_size=3,
                    strides=2,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=0.0, stddev=0.02, dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv2')
                norm2 = ops._norm(conv2)
                relu2 = ops.relu(norm2)
            with tf.variable_scope("conv3", reuse=self.reuse):
                conv3 = tf.layers.conv2d(
                    inputs=relu2,
                    filters=4 * self.ngf,
                    kernel_size=3,
                    strides=2,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=0.0, stddev=0.02, dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv3')
                norm3 = ops._norm(conv3)
                relu3 = ops.relu(norm3)
            with tf.variable_scope("conv4_1", reuse=self.reuse):
                conv4_1 = tf.layers.conv2d(
                    inputs=relu3,
                    filters=2 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=0.0, stddev=0.02, dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv4_1')
                norm4_1 = ops._norm(conv4_1)
                relu4_1 = ops.relu(norm4_1)
            with tf.variable_scope("conv5_1", reuse=self.reuse):
                output_1 = tf.layers.conv2d(
                    inputs=relu4_1,
                    filters=1,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=0.0, stddev=0.02, dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv5_1')

            with tf.variable_scope("conv4_2", reuse=self.reuse):
                conv4_2 = tf.layers.conv2d(
                    inputs=relu3,
                    filters=2 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=0.0, stddev=0.02, dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv4_2')
                norm4_2 = ops._norm(conv4_2)
                relu4_2 = ops.relu(norm4_2)
            with tf.variable_scope("conv5_2", reuse=self.reuse):
                output_2 = tf.layers.conv2d(
                    inputs=relu4_2,
                    filters=1,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=0.0, stddev=0.02, dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv5_2')

        self.reuse = True
        self.variables = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES,
                                           scope=self.name)

        return output_1, output_2
예제 #6
0
    def __call__(self, EC_input):
        """
        Args:
          input: batch_size x width x height x 3
        Returns:
          output: same size as input
        """

        with tf.variable_scope(self.name):
            EC_input = tf.nn.dropout(EC_input, keep_prob=self.keep_prob)
            with tf.variable_scope("conv1", reuse=self.reuse):
                conv1 = tf.layers.conv2d(inputs=EC_input, filters=self.ngf, kernel_size=3, strides=1, padding="SAME",
                                         activation=None,
                                         kernel_initializer=tf.random_normal_initializer(
                                             mean=1.0 / (9.0 * 1), stddev=0.000001, dtype=tf.float32),
                                         bias_initializer=tf.constant_initializer(0.0), name='conv1')
                norm1 = ops._norm(conv1, self.is_training, self.norm)
                relu1 = ops.relu(norm1)
            with tf.variable_scope("conv2", reuse=self.reuse):
                conv2 = tf.layers.conv2d(inputs=relu1, filters=self.ngf, kernel_size=3, strides=1, padding="SAME",
                                         activation=None,
                                         kernel_initializer=tf.random_normal_initializer(
                                             mean=1.0 / (9.0 * self.ngf), stddev=0.000001, dtype=tf.float32),
                                         bias_initializer=tf.constant_initializer(0.0), name='conv2')
                norm2 = ops._norm(conv2, self.is_training, self.norm)
                relu2 = ops.relu(norm2)
            # pool1
            with tf.variable_scope("conv3", reuse=self.reuse):
                conv3 = tf.layers.conv2d(inputs=relu2, filters=2 * self.ngf, kernel_size=3,
                                         strides=self.slice_stride,
                                         padding="SAME",
                                         activation=None,
                                         kernel_initializer=tf.random_normal_initializer(
                                             mean=1.0 / (9.0 * self.ngf), stddev=0.000001, dtype=tf.float32),
                                         bias_initializer=tf.constant_initializer(0.0), name='conv3')
                norm3 = ops._norm(conv3, self.is_training, self.norm)
                relu3 = ops.relu(norm3)
            # w/2,h/2
            with tf.variable_scope("conv4", reuse=self.reuse):
                conv4 = tf.layers.conv2d(inputs=relu3, filters=4 * self.ngf, kernel_size=3, strides=1,
                                         padding="SAME",
                                         activation=None,
                                         kernel_initializer=tf.random_normal_initializer(
                                             mean=1.0 / (9.0 * 2 * self.ngf), stddev=0.000001, dtype=tf.float32),
                                         bias_initializer=tf.constant_initializer(0.0), name='conv4')
                norm4 = ops._norm(conv4, self.is_training, self.norm)
                relu4 = ops.relu(norm4)
            with tf.variable_scope("conv5", reuse=self.reuse):
                conv5 = tf.layers.conv2d(inputs=relu4, filters=4 * self.ngf, kernel_size=3, strides=1,
                                         padding="SAME",
                                         activation=None,
                                         kernel_initializer=tf.random_normal_initializer(
                                             mean=1.0 / (9.0 * 4 * self.ngf), stddev=0.000001, dtype=tf.float32),
                                         bias_initializer=tf.constant_initializer(0.0), name='conv5')
                norm5 = ops._norm(conv5, self.is_training, self.norm)
                relu5 = tf.nn.relu(norm5)
            # pool2
            with tf.variable_scope("conv6", reuse=self.reuse):
                conv6 = tf.layers.conv2d(inputs=relu5, filters=8 * self.ngf, kernel_size=3,
                                         strides=self.slice_stride,
                                         padding="SAME",
                                         activation=None,
                                         kernel_initializer=tf.random_normal_initializer(
                                             mean=1.0 / (9.0 * 4 * self.ngf), stddev=0.000001, dtype=tf.float32),
                                         bias_initializer=tf.constant_initializer(0.0), name='conv6')
                norm6 = ops._norm(conv6, self.is_training, self.norm)
                relu6 = ops.relu(norm6)
            # w/4,h/4
            with tf.variable_scope("conv7", reuse=self.reuse):
                conv7 = tf.layers.conv2d(inputs=relu6, filters=8 * self.ngf, kernel_size=3, strides=1,
                                         padding="SAME",
                                         activation=None,
                                         kernel_initializer=tf.random_normal_initializer(
                                             mean=1.0 / (9.0 * 8 * self.ngf), stddev=0.000001, dtype=tf.float32),
                                         bias_initializer=tf.constant_initializer(0.0), name='conv7')
                norm7 = ops._norm(conv7, self.is_training, self.norm)
                output = ops.relu(norm7)

        self.reuse = True
        self.variables = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES, scope=self.name)
        return output
예제 #7
0
    def __call__(self, DC_input):
        """
        Args:
          input: batch_size x width x height x N
        Returns:
          output: same size as input
        """
        with tf.variable_scope(self.name, reuse=self.reuse):
            DC_input = tf.nn.dropout(DC_input, keep_prob=self.keep_prob)
            with tf.variable_scope("conv1", reuse=self.reuse):
                conv1 = tf.layers.conv2d(
                    inputs=DC_input,
                    filters=8 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 8 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv1')
                norm1 = ops._norm(conv1, self.is_training, self.norm)
                relu1 = ops.relu(norm1)
            with tf.variable_scope("deconv1_r", reuse=self.reuse):
                resize1 = ops.uk_resize(relu1,
                                        reuse=self.reuse,
                                        name='resize1')
                deconv1_r = tf.layers.conv2d(
                    inputs=resize1,
                    filters=4 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 8 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='deconv1_r')
                deconv1_norm1_r = ops._norm(deconv1_r, self.is_training,
                                            self.norm)
                add1 = ops.relu(deconv1_norm1_r)
            with tf.variable_scope("add1_conv1", reuse=self.reuse):
                add1_conv1 = tf.layers.conv2d(
                    inputs=add1,
                    filters=4 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 4 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='add1_conv1')
                add1_norm1 = ops._norm(add1_conv1, self.is_training, self.norm)
                add1_relu1 = ops.relu(add1_norm1)
            with tf.variable_scope("add1_conv2", reuse=self.reuse):
                add1_conv2 = tf.layers.conv2d(
                    inputs=add1_relu1,
                    filters=4 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 4 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='add1_conv2')
                add1_norm2 = ops._norm(add1_conv2, self.is_training, self.norm)
                add1_relu2 = ops.relu(add1_norm2)
            with tf.variable_scope("deconv2_r", reuse=self.reuse):
                resize2 = ops.uk_resize(add1_relu2,
                                        reuse=self.reuse,
                                        name='resize1')
                deconv2_r = tf.layers.conv2d(
                    inputs=resize2,
                    filters=2 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 4 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='deconv2_r')
                deconv2_norm1_r = ops._norm(deconv2_r, self.is_training,
                                            self.norm)
                add2 = ops.relu(deconv2_norm1_r)
            with tf.variable_scope("add2_conv1", reuse=self.reuse):
                add2_conv1 = tf.layers.conv2d(
                    inputs=add2,
                    filters=2 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 2 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='add2_conv1')
                add2_norm1 = ops._norm(add2_conv1, self.is_training, self.norm)
                add2_relu1 = ops.relu(add2_norm1)
            with tf.variable_scope("add2_conv2", reuse=self.reuse):
                add2_conv = tf.layers.conv2d(
                    inputs=add2_relu1,
                    filters=2 * self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 2 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='add2_conv2')
                add2_norm2 = ops._norm(add2_conv, self.is_training, self.norm)
                add2_relu2 = ops.relu(add2_norm2)
            with tf.variable_scope("conv2", reuse=self.reuse):
                conv2 = tf.layers.conv2d(
                    inputs=add2_relu2,
                    filters=self.ngf,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * 2 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv2')
                norm2 = ops._norm(conv2, self.is_training, self.norm)
                relu2 = ops.relu(norm2)
            with tf.variable_scope("lastconv", reuse=self.reuse):
                lastconv = tf.layers.conv2d(
                    inputs=relu2,
                    filters=self.output_channl,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=1.0 / (9.0 * self.ngf),
                        stddev=0.000001,
                        dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='lastconv')
                lastnorm = ops._norm(lastconv, self.is_training, self.norm)
                output = tf.nn.sigmoid(lastnorm)

        self.reuse = True
        self.variables = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES,
                                           scope=self.name)
        return output
    def __call__(self, D_input, class_vt, location_vt):
        """
        Args:
          input: batch_size x image_size x image_size x 3
        Returns:
          output: 4D tensor batch_size x out_size x out_size x 1 (default 1x5x5x1)
                  filled with 0.9 if real, 0.0 if fake
        """

        with tf.variable_scope(self.name, reuse=self.reuse):
            D_input = tf.nn.dropout(D_input, keep_prob=self.keep_prob)
            with tf.variable_scope("class_vt_dense0", reuse=self.reuse):
                class_vt = tf.layers.flatten(class_vt)
                dense0 = tf.layers.dense(class_vt, units=1024, name="dense0")
                dense0 = tf.reshape(dense0, shape=[-1, 32, 32, 1])
                resize0 = tf.image.resize_images(dense0, [512, 512], method=1)
            with tf.variable_scope("location_vt_dense0", reuse=self.reuse):
                location_vt = tf.layers.flatten(location_vt)
                dense1 = tf.layers.dense(location_vt,
                                         units=1024,
                                         name="dense1")
                dense1 = tf.reshape(dense1, shape=[-1, 32, 32, 1])
                resize1 = tf.image.resize_images(dense1, [512, 512], method=1)
            with tf.variable_scope("concat0", reuse=self.reuse):
                concat0 = tf.reshape(tf.concat([D_input, resize0, resize1],
                                               axis=-1),
                                     shape=[-1, 512, 512, 5])
            with tf.variable_scope("conv0", reuse=self.reuse):
                conv0 = tf.layers.conv2d(
                    inputs=concat0,
                    filters=self.ngf,
                    kernel_size=5,
                    strides=self.slice_stride,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=0.0, stddev=0.02, dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv0')
                norm0 = ops._norm(conv0, self.is_training, self.norm)
                relu0 = ops.relu(norm0)
            with tf.variable_scope("conv1", reuse=self.reuse):
                conv1 = tf.layers.conv2d(
                    inputs=relu0,
                    filters=self.ngf,
                    kernel_size=5,
                    strides=self.slice_stride,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=0.0, stddev=0.02, dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv1')
                norm1 = ops._norm(conv1, self.is_training, self.norm)
                relu1 = ops.relu(norm1)
            with tf.variable_scope("conv2", reuse=self.reuse):
                conv2 = tf.layers.conv2d(
                    inputs=relu1,
                    filters=2 * self.ngf,
                    kernel_size=3,
                    strides=self.slice_stride,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=0.0, stddev=0.02, dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv2')
                norm2 = ops._norm(conv2, self.is_training, self.norm)
                relu2 = ops.relu(norm2)
            with tf.variable_scope("conv3", reuse=self.reuse):
                conv3 = tf.layers.conv2d(
                    inputs=relu2,
                    filters=2 * self.ngf,
                    kernel_size=3,
                    strides=self.slice_stride,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=0.0, stddev=0.02, dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv3')
                norm3 = ops._norm(conv3, self.is_training, self.norm)
                relu3 = ops.relu(norm3)
            with tf.variable_scope("conv4", reuse=self.reuse):
                conv4_1 = tf.layers.conv2d(
                    inputs=relu3,
                    filters=self.ngf,
                    kernel_size=3,
                    strides=self.slice_stride,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=0.0, stddev=0.02, dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv4')
                norm4_1 = ops._norm(conv4_1, self.is_training, self.norm)
                relu4_1 = ops.relu(norm4_1)
            with tf.variable_scope("conv5", reuse=self.reuse):
                output = tf.layers.conv2d(
                    inputs=relu4_1,
                    filters=self.output_channl,
                    kernel_size=3,
                    strides=1,
                    padding="SAME",
                    activation=None,
                    kernel_initializer=tf.random_normal_initializer(
                        mean=0.0, stddev=0.02, dtype=tf.float32),
                    bias_initializer=tf.constant_initializer(0.0),
                    name='conv5')

        self.reuse = True
        self.variables = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES,
                                           scope=self.name)

        return output