def testCreateConv2DTransposeWithStrides(self): height, width = 6, 8 # Test strides tuple images = random_ops.random_uniform((5, height, width, 3), seed=1) layer = conv_layers.Conv2DTranspose(32, [3, 3], strides=(2, 2), padding='same') output = layer.apply(images) self.assertListEqual(output.get_shape().as_list(), [5, height * 2, width * 2, 32]) # Test strides integer layer = conv_layers.Conv2DTranspose(32, [3, 3], strides=2, padding='same') output = layer.apply(images) self.assertListEqual(output.get_shape().as_list(), [5, height * 2, width * 2, 32]) # Test unequal strides layer = conv_layers.Conv2DTranspose(32, [3, 3], strides=(2, 1), padding='same') output = layer.apply(images) self.assertListEqual(output.get_shape().as_list(), [5, height * 2, width, 32])
def testConv2DTransposePaddingSame(self): height, width = 7, 9 images = random_ops.random_uniform((5, height, width, 32), seed=1) layer = conv_layers.Conv2DTranspose( 64, images.get_shape()[1:3], padding='same') output = layer.apply(images) self.assertListEqual(output.get_shape().as_list(), [5, height, width, 64])
def testConv2DTransposeBiasRegularizer(self): height, width = 7, 9 images = random_ops.random_uniform((5, height, width, 4)) reg = lambda x: 0.1 * math_ops.reduce_sum(x) layer = conv_layers.Conv2DTranspose(32, [3, 3], bias_regularizer=reg) layer.apply(images) loss_keys = ops.get_collection(ops.GraphKeys.REGULARIZATION_LOSSES) self.assertEqual(len(loss_keys), 1) self.assertListEqual(layer.losses, loss_keys)
def testCreateConv2DTransposeIntegerKernelSize(self): height, width = 7, 9 images = random_ops.random_uniform((5, height, width, 4)) layer = conv_layers.Conv2DTranspose(32, 3) output = layer.apply(images) self.assertListEqual(output.get_shape().as_list(), [5, height + 2, width + 2, 32]) self.assertListEqual(layer.kernel.get_shape().as_list(), [3, 3, 32, 4]) self.assertListEqual(layer.bias.get_shape().as_list(), [32])
def testCreateConv2DTransposeChannelsFirst(self): height, width = 7, 9 images = random_ops.random_uniform((5, 4, height, width)) layer = conv_layers.Conv2DTranspose(32, [3, 3], data_format='channels_first') output = layer.apply(images) self.assertListEqual(output.get_shape().as_list(), [5, 32, height + 2, width + 2]) self.assertListEqual(layer.kernel.get_shape().as_list(), [3, 3, 32, 4]) self.assertListEqual(layer.bias.get_shape().as_list(), [32])
def testCreateConv2DTranspose(self): height, width = 7, 9 images = random_ops.random_uniform((5, height, width, 4)) layer = conv_layers.Conv2DTranspose(32, [3, 3], activation=nn_ops.relu) output = layer.apply(images) self.assertEqual(output.op.name, 'conv2d_transpose/Relu') self.assertListEqual(output.get_shape().as_list(), [5, height + 2, width + 2, 32]) self.assertListEqual(layer.kernel.get_shape().as_list(), [3, 3, 32, 4]) self.assertListEqual(layer.bias.get_shape().as_list(), [32])
def testConstraints(self): k_constraint = lambda x: x / math_ops.reduce_sum(x) b_constraint = lambda x: x / math_ops.reduce_max(x) layer = conv_layers.Conv2DTranspose(2, 3, kernel_constraint=k_constraint, bias_constraint=b_constraint) inputs = random_ops.random_uniform((5, 3, 3, 5), seed=1) layer(inputs) self.assertEqual(layer.kernel_constraint, k_constraint) self.assertEqual(layer.bias_constraint, b_constraint)