示例#1
0
    def fromrgb(img, block_id, scope='fromrgb'):
        with tf.variable_scope(scope):
            net = img
            if params.fromrgb_use_n_img_diffs:
                for d in range(
                        1,
                        min(params.fromrgb_use_n_img_diffs, block_id - 2) + 1):
                    scale = 2**d
                    tf.logging.info(
                        'D.block_%d fromrgb uses img diff with scale %d',
                        block_id, scale)
                    img_down = img
                    img_down = network_utils.downscale2d(img_down, scale)
                    img_down = network_utils.upscale2d(img_down, scale)
                    net = tf.concat([net, img - img_down], axis=1)
            tf.logging.info('D.block_%d fromrgb input net shape %s', block_id,
                            net.shape.as_list())

            if params.second_conv_channels_x2:
                channels = channels_at_res(block_id - 1)
            else:
                channels = channels_at_res(block_id)
            net = condition(net)
            net = network_utils.conv(net,
                                     filters=channels,
                                     kernel_size=1,
                                     weight_norm=params.weight_norm)
            net = tf.nn.leaky_relu(net)
            return net
示例#2
0
 def _append_channels(net, infogan_vars, infogan_num_vars, block_id):
     if infogan_vars is None:
         return net
     with tf.variable_scope('append_channels'):
         if net.shape.ndims == 2:
             net = tf.concat([net, infogan_vars], axis=1)
         else:
             infogan_channels = tf.reshape(
                 infogan_vars, [gpu_batch_size, infogan_num_vars, 1, 1])
             infogan_num_channels = (net.shape.as_list()[1] /
                                     params.append_channels_div)
             tf.logging.info(
                 'Block %d, infogan_input_method append_channels, '
                 'infogan_num_channels %d', block_id, infogan_num_channels)
             infogan_channels = network_utils.conv(
                 infogan_channels,
                 filters=infogan_num_channels,
                 kernel_size=1,
                 weight_norm=params.weight_norm)
             infogan_channels = tf.nn.leaky_relu(infogan_channels)
             side = net.shape.as_list()[-1]
             infogan_channels = tf.tile(infogan_channels,
                                        [1, 1, side, side])
             net = tf.concat([net, infogan_channels], axis=1)
             tf.logging.info(
                 'Block %d, infogan_input_method append_channels, '
                 'new net shape %s', block_id, net.shape.as_list())
         return net
示例#3
0
 def torgb(net, scope='torgb', block_id=None):
     with tf.variable_scope(scope):
         net = condition(net, block_id)
         net = network_utils.conv(net,
                                  filters=3,
                                  kernel_size=1,
                                  weight_norm=params.weight_norm)
         if params.torgb_tanh:
             net = tf.nn.tanh(net)
         return net
示例#4
0
 def CCNA(net, block_id, scope):
     with tf.variable_scope(scope):
         net = condition(net, block_id)
         net = network_utils.conv(net,
                                  filters=channels_at_res(block_id),
                                  weight_norm=params.weight_norm,
                                  kernel_size=params.kernel_size)
         net = network_utils.norm(net,
                                  axis=1,
                                  version=params.norm,
                                  is_training=is_training,
                                  gpu_id=gpu_id,
                                  per_gpu=params.norm_per_gpu)
         net = tf.nn.leaky_relu(net)
         if params.pn_after_act: net = network_utils.pixel_norm(net, axis=1)
         return net