Example #1
0
def block_no_sn(x, labels, out_channels, num_classes, is_training, name):
    """Builds the residual blocks used in the generator.

  Compared with block, optimized_block always downsamples the spatial resolution
  of the input vector by a factor of 4.

  Args:
    x: The 4D input vector.
    labels: The conditional labels in the generation.
    out_channels: Number of features in the output layer.
    num_classes: Number of classes in the labels.
    name: The variable scope name for the block.
  Returns:
    A `Tensor` representing the output of the operation.
  """
    with tf.variable_scope(name):
        bn0 = ops.ConditionalBatchNorm(num_classes, name='cbn_0')
        bn1 = ops.ConditionalBatchNorm(num_classes, name='cbn_1')
        x_0 = x
        x = tf.nn.relu(bn0(x, labels, is_training))
        x = usample(x)
        x = ops.conv2d(x, out_channels, 3, 3, 1, 1, name='conv1')
        x = tf.nn.relu(bn1(x, labels, is_training))
        x = ops.conv2d(x, out_channels, 3, 3, 1, 1, name='conv2')

        x_0 = usample(x_0)
        x_0 = ops.conv2d(x_0, out_channels, 1, 1, 1, 1, name='conv3')

        return x_0 + x
Example #2
0
def block(x, labels, out_channels, num_classes, is_training, CGN, CGN_groups,
          name):
    with tf.variable_scope(name):
        if CGN:
            norm0 = ops.ConditionalGroupNorm(num_classes,
                                             CGN_groups,
                                             name='cgn_0')
            norm1 = ops.ConditionalGroupNorm(num_classes,
                                             CGN_groups,
                                             name='cgn_1')
        else:
            norm0 = ops.ConditionalBatchNorm(num_classes, name='cbn_0')
            norm1 = ops.ConditionalBatchNorm(num_classes, name='cbn_1')

        x_0 = x
        x = tf.nn.relu(norm0(x, labels, is_training))
        x = usample(x)
        x = ops.snconv2d(x, out_channels, 3, 3, 1, 1, name='snconv1')
        x = tf.nn.relu(norm1(x, labels, is_training))
        x = ops.snconv2d(x, out_channels, 3, 3, 1, 1, name='snconv2')

        x_0 = usample(x_0)
        x_0 = ops.snconv2d(x_0, out_channels, 1, 1, 1, 1, name='snconv3')

        return x_0 + x
Example #3
0
def block(x, labels, out_channels, num_classes, is_training, name):
    with tf.variable_scope(name):
        bn0 = ops.ConditionalBatchNorm(num_classes, name='cbn_0')
        bn1 = ops.ConditionalBatchNorm(num_classes, name='cbn_1')
        x_0 = x
        x = tf.nn.relu(bn0(x, labels, is_training))
        x = usample(x)
        x = ops.snconv2d(x, out_channels, 3, 3, 1, 1, name='snconv1')
        x = tf.nn.relu(bn1(x, labels, is_training))
        x = ops.snconv2d(x, out_channels, 3, 3, 1, 1, name='snconv2')

        x_0 = usample(x_0)
        x_0 = ops.snconv2d(x_0, out_channels, 1, 1, 1, 1, name='snconv3')

        return x_0 + x
Example #4
0
def class_conditional_generator_block(x, labels, out_channels, num_classes,
                                      is_training, name):
    with tf.variable_scope(name):
        bn0 = ops.ConditionalBatchNorm(num_classes, name='cbn_0')
        bn1 = ops.ConditionalBatchNorm(num_classes, name='cbn_1')
        x_0 = x
        x = tf.nn.relu(bn0(x, labels, is_training))
        x = resnet_architecture.get_conv(x, None, out_channels, "up",
                                         'snconv1', True)
        # x = usample(x)
        # x = ops.snconv2d(x, out_channels, 3, 3, 1, 1, name='snconv1')
        x = tf.nn.relu(bn1(x, labels, is_training))
        x = resnet_architecture.get_conv(x, None, out_channels, "none",
                                         'snconv2', True)
        # x = ops.snconv2d(x, out_channels, 3, 3, 1, 1, name='snconv2')

        x_0 = resnet_architecture.get_conv(x_0, None, out_channels, "up",
                                           'snconv3', True)
        # x_0 = usample(x_0)
        # x_0 = ops.snconv2d(x_0, out_channels, 1, 1, 1, 1, name='snconv3')

        return x_0 + x