def test_deconvolution_tuple_padding(self): network = layers.join( layers.Input((10, 10, 3)), layers.Convolution((3, 3, 7), padding=(9, 3)), layers.Deconvolution((3, 3, 4), padding=(9, 3)), ) shapes = network.output_shapes_per_layer shapes = {l: shape_to_tuple(s) for l, s in shapes.items()} self.assertSequenceEqual( shapes, { network.layers[0]: (None, 10, 10, 3), network.layers[1]: (None, 26, 14, 7), network.layers[2]: (None, 10, 10, 4), }) input_value = asfloat(np.random.random((1, 10, 10, 3))) actual_output = self.eval(network.output(input_value)) self.assertEqual(actual_output.shape, (1, 10, 10, 4))
def test_deconv_unknown_input_width_and_height(self): network = layers.join( layers.Input((None, None, 3)), layers.Convolution((3, 3, 7)), layers.Deconvolution((3, 3, 4)), ) shapes = network.output_shapes_per_layer shapes = {l: shape_to_tuple(s) for l, s in shapes.items()} self.assertDictEqual( shapes, { network.layers[0]: (None, None, None, 3), network.layers[1]: (None, None, None, 7), network.layers[2]: (None, None, None, 4), }) input_value = asfloat(np.random.random((1, 10, 10, 3))) actual_output = self.eval(network.output(input_value)) self.assertEqual(actual_output.shape, (1, 10, 10, 4)) input_value = asfloat(np.random.random((1, 7, 7, 3))) actual_output = self.eval(network.output(input_value)) self.assertEqual(actual_output.shape, (1, 7, 7, 4))
def assertShapesEqual(self, shape1, shape2, *args, **kwargs): shape1 = shape_to_tuple(shape1) shape2 = shape_to_tuple(shape2) self.assertEqual(shape1, shape2, *args, **kwargs)