def testCreateConv3DTransposeWithStrides(self): depth, height, width = 4, 6, 8 # Test strides tuple. volumes = random_ops.random_uniform((5, depth, height, width, 32), seed=1) layer = conv_layers.Conv3DTranspose(4, [3, 3, 3], strides=(2, 2, 2), padding='same') output = layer.apply(volumes) self.assertListEqual(output.get_shape().as_list(), [5, depth * 2, height * 2, width * 2, 4]) # Test strides integer. layer = conv_layers.Conv3DTranspose(4, [3, 3, 3], strides=2, padding='same') output = layer.apply(volumes) self.assertListEqual(output.get_shape().as_list(), [5, depth * 2, height * 2, width * 2, 4]) # Test unequal strides. layer = conv_layers.Conv3DTranspose(4, [3, 3, 3], strides=(2, 1, 1), padding='same') output = layer.apply(volumes) self.assertListEqual(output.get_shape().as_list(), [5, depth * 2, height, width, 4])
def testConv3DTransposePaddingSame(self): depth, height, width = 5, 7, 9 volumes = random_ops.random_uniform((5, depth, height, width, 64), seed=1) layer = conv_layers.Conv3DTranspose( 32, volumes.get_shape()[1:4], padding='same') output = layer.apply(volumes) self.assertListEqual(output.get_shape().as_list(), [5, depth, height, width, 32])
def testConv3DTransposeBiasRegularizer(self): depth, height, width = 5, 7, 9 volumes = random_ops.random_uniform((5, depth, height, width, 32)) reg = lambda x: 0.1 * math_ops.reduce_sum(x) layer = conv_layers.Conv3DTranspose(4, [3, 3, 3], bias_regularizer=reg) layer.apply(volumes) loss_keys = ops.get_collection(ops.GraphKeys.REGULARIZATION_LOSSES) self.assertEqual(len(loss_keys), 1) self.assertListEqual(layer.losses, loss_keys)
def testCreateConv3DTransposeIntegerKernelSize(self): depth, height, width = 5, 7, 9 volumes = random_ops.random_uniform((5, depth, height, width, 32)) layer = conv_layers.Conv3DTranspose(4, 3) output = layer.apply(volumes) self.assertListEqual(output.get_shape().as_list(), [5, depth + 2, height + 2, width + 2, 4]) self.assertListEqual(layer.kernel.get_shape().as_list(), [3, 3, 3, 4, 32]) self.assertListEqual(layer.bias.get_shape().as_list(), [4])
def testCreateConv3DTransposeChannelsFirst(self): depth, height, width = 5, 7, 9 volumes = random_ops.random_uniform((5, 32, depth, height, width)) layer = conv_layers.Conv3DTranspose( 4, [3, 3, 3], data_format='channels_first') output = layer.apply(volumes) self.assertListEqual(output.get_shape().as_list(), [5, 4, depth + 2, height + 2, width + 2]) self.assertListEqual(layer.kernel.get_shape().as_list(), [3, 3, 3, 4, 32]) self.assertListEqual(layer.bias.get_shape().as_list(), [4])
def testCreateConv3DTranspose(self): depth, height, width = 5, 7, 9 volumes = random_ops.random_uniform((5, depth, height, width, 32)) layer = conv_layers.Conv3DTranspose(4, [3, 3, 3], activation=nn_ops.relu) output = layer.apply(volumes) self.assertEqual(output.op.name, 'conv3d_transpose/Relu') self.assertListEqual(output.get_shape().as_list(), [5, depth + 2, height + 2, width + 2, 4]) self.assertListEqual(layer.kernel.get_shape().as_list(), [3, 3, 3, 4, 32]) self.assertListEqual(layer.bias.get_shape().as_list(), [4])
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.Conv3DTranspose(2, 3, kernel_constraint=k_constraint, bias_constraint=b_constraint) inputs = random_ops.random_uniform((5, 3, 3, 3, 5), seed=1) layer(inputs) self.assertEqual(layer.kernel_constraint, k_constraint) self.assertEqual(layer.bias_constraint, b_constraint)