Ejemplo n.º 1
0
    def build(self, z, train):
        with tf.variable_scope(self.scope_name, reuse=tf.AUTO_REUSE):
            batch_size = tf.shape(z)[0]

            layers = [z]

            with tf.variable_scope("layer0"):
                layers.append(linear(layers[-1], 128))
                layers.append(tf.nn.relu(layers[-1]))
                layers.append(batch_norm()(layers[-1], train=train))

            with tf.variable_scope("layer1"):
                layers.append(linear(layers[-1], 4 * 4 * 64))
                layers.append(tf.nn.relu(layers[-1]))
                layers.append(batch_norm()(layers[-1], train=train))
                layers.append(tf.reshape(layers[-1], [-1, 4, 4, 64]))

            with tf.variable_scope("layer2"):
                layers.append(
                    deconv2d(layers[-1], [batch_size, 8, 8, 64],
                             d_h=self.stride,
                             d_w=self.stride,
                             k_h=self.kernel,
                             k_w=self.kernel))
                layers.append(lrelu(layers[-1]))
                layers.append(batch_norm()(layers[-1], train=train))

            with tf.variable_scope("layer3"):
                layers.append(
                    deconv2d(layers[-1], [batch_size, 16, 16, 32],
                             d_h=self.stride,
                             d_w=self.stride,
                             k_h=self.kernel,
                             k_w=self.kernel))
                layers.append(lrelu(layers[-1]))
                layers.append(batch_norm()(layers[-1], train=train))

            with tf.variable_scope("layer4"):
                layers.append(
                    deconv2d(layers[-1], [batch_size, 32, 32, 32],
                             d_h=self.stride,
                             d_w=self.stride,
                             k_h=self.kernel,
                             k_w=self.kernel))
                layers.append(lrelu(layers[-1]))
                layers.append(batch_norm()(layers[-1], train=train))

            with tf.variable_scope("layer5"):
                layers.append(
                    deconv2d(layers[-1], [
                        batch_size, self.output_height, self.output_width,
                        self.output_depth
                    ],
                             d_h=self.stride,
                             d_w=self.stride,
                             k_h=self.kernel,
                             k_w=self.kernel))
                layers.append(tf.nn.sigmoid(layers[-1]))

            return layers[-1], layers
Ejemplo n.º 2
0
    def build(self, images, train):
        with tf.variable_scope(self.scope_name, reuse=tf.AUTO_REUSE):
            layers = [images]
            with tf.variable_scope("layer0"):
                layers.append(conv2d(
                    layers[-1],
                    32,
                    d_h=self.stride,
                    d_w=self.stride,
                    k_h=self.kernel,
                    k_w=self.kernel,
                    sn_op=None))
                layers.append(lrelu(layers[-1]))
            with tf.variable_scope("layer1"):
                layers.append(conv2d(
                    layers[-1],
                    32,
                    d_h=self.stride,
                    d_w=self.stride,
                    k_h=self.kernel,
                    k_w=self.kernel,
                    sn_op=None))
                layers.append(lrelu(layers[-1]))
                layers.append(batch_norm()(layers[-1], train=train))
            with tf.variable_scope("layer2"):
                layers.append(conv2d(
                    layers[-1],
                    64,
                    d_h=self.stride,
                    d_w=self.stride,
                    k_h=self.kernel,
                    k_w=self.kernel,
                    sn_op=None))
                layers.append(lrelu(layers[-1]))
                layers.append(batch_norm()(layers[-1], train=train))
            with tf.variable_scope("layer3"):
                layers.append(conv2d(
                    layers[-1],
                    64,
                    d_h=self.stride,
                    d_w=self.stride,
                    k_h=self.kernel,
                    k_w=self.kernel,
                    sn_op=None))
                layers.append(lrelu(layers[-1]))
                layers.append(batch_norm()(layers[-1], train=train))
            with tf.variable_scope("layer4"):
                layers.append(linear(layers[-1], 128, sn_op=None))
                layers.append(lrelu(layers[-1]))
                layers.append(batch_norm()(layers[-1], train=train))
            with tf.variable_scope("layer5"):
                layers.append(linear(layers[-1], self.output_length))

            return layers[-1], layers
Ejemplo n.º 3
0
    def build(self, image, train):
        with tf.variable_scope(self.scope_name, reuse=tf.AUTO_REUSE):
            layers = [image]
            with tf.variable_scope("layer0"):
                layers.append(
                    conv2d(layers[-1],
                           self.start_depth,
                           d_h=self.stride,
                           d_w=self.stride,
                           k_h=self.kernel,
                           k_w=self.kernel))
                layers.append(lrelu(layers[-1]))

            with tf.variable_scope("layer1"):
                layers.append(
                    conv2d(layers[-1],
                           self.start_depth * 2,
                           d_h=self.stride,
                           d_w=self.stride,
                           k_h=self.kernel,
                           k_w=self.kernel))
                layers.append(batch_norm()(layers[-1], train=train))
                layers.append(lrelu(layers[-1]))

            with tf.variable_scope("layer2"):
                layers.append(
                    conv2d(layers[-1],
                           self.start_depth * 4,
                           d_h=self.stride,
                           d_w=self.stride,
                           k_h=self.kernel,
                           k_w=self.kernel))
                layers.append(batch_norm()(layers[-1], train=train))
                layers.append(lrelu(layers[-1]))

            with tf.variable_scope("layer3"):
                layers.append(
                    conv2d(layers[-1],
                           self.start_depth * 8,
                           d_h=self.stride,
                           d_w=self.stride,
                           k_h=self.kernel,
                           k_w=self.kernel))
                layers.append(batch_norm()(layers[-1], train=train))
                layers.append(lrelu(layers[-1]))

            with tf.variable_scope("layer4"):
                layers.append(linear(layers[-1], self.output_length))

            return layers[-1], layers
Ejemplo n.º 4
0
    def build(self, z, train):
        with tf.variable_scope(self.scope_name, reuse=tf.AUTO_REUSE):
            layers = [z]

            for i in range(self.num_layers - 1):
                with tf.variable_scope("layer{}".format(i)):
                    layers.append(linear(layers[-1], self.l_dim))
                    layers.append(lrelu(layers[-1]))
            with tf.variable_scope("layer{}".format(self.num_layers - 1)):
                layers.append(linear(layers[-1], 2))
                logit = layers[-1]
                layers.append(tf.nn.softmax(layers[-1]))
                prob = layers[-1]

            return logit, prob, layers
Ejemplo n.º 5
0
    def build(self, image, train, sn_op):
        with tf.variable_scope(self.scope_name, reuse=tf.AUTO_REUSE):
            with tf.variable_scope("shared"):
                layers = [image]
                with tf.variable_scope("layer0"):
                    layers.append(
                        conv2d(layers[-1],
                               self.start_depth,
                               d_h=self.stride,
                               d_w=self.stride,
                               k_h=self.kernel,
                               k_w=self.kernel,
                               sn_op=sn_op))
                    layers.append(lrelu(layers[-1]))

                with tf.variable_scope("layer1"):
                    layers.append(
                        conv2d(layers[-1],
                               self.start_depth * 2,
                               d_h=self.stride,
                               d_w=self.stride,
                               k_h=self.kernel,
                               k_w=self.kernel,
                               sn_op=sn_op))
                    layers.append(lrelu(layers[-1]))

                with tf.variable_scope("layer2"):
                    layers.append(
                        conv2d(layers[-1],
                               self.start_depth * 4,
                               d_h=self.stride,
                               d_w=self.stride,
                               k_h=self.kernel,
                               k_w=self.kernel,
                               sn_op=sn_op))
                    layers.append(lrelu(layers[-1]))

                with tf.variable_scope("layer3"):
                    layers.append(
                        conv2d(layers[-1],
                               self.start_depth * 8,
                               d_h=self.stride,
                               d_w=self.stride,
                               k_h=self.kernel,
                               k_w=self.kernel,
                               sn_op=sn_op))

                    layers.append(lrelu(layers[-1]))

            with tf.variable_scope("x"):
                image_layers = [layers[-1]]
                with tf.variable_scope("layer0"):
                    image_layers.append(
                        linear(image_layers[-1], 1, sn_op=sn_op))
                    image_layers.append(tf.nn.sigmoid(image_layers[-1]))

            with tf.variable_scope("q"):
                q_layers = [layers[-1]]
                with tf.variable_scope("layer0"):
                    q_layers.append(
                        linear(q_layers[-1], self.output_length, sn_op=sn_op))

            layers.extend(image_layers)
            layers.extend(q_layers)

            return image_layers[-1], q_layers[-1], layers