Exemplo n.º 1
0
    def test_simple(self):
        # channels_last
        with self.test_session():
            # create simple UpsampleLike layer
            upsample_like_layer = layers.UpsampleLike()

            # create input source
            source = np.zeros((1, 2, 2, 1), dtype=K.floatx())
            source = K.variable(source)
            target = np.zeros((1, 5, 5, 1), dtype=K.floatx())
            expected = target
            target = K.variable(target)

            # compute output
            computed_shape = upsample_like_layer.compute_output_shape(
                [source.shape, target.shape])

            actual = upsample_like_layer.call([source, target])
            actual = K.get_value(actual)

            self.assertEqual(actual.shape, computed_shape)
            self.assertAllEqual(actual, expected)
        # channels_first
        with self.test_session():
            # create simple UpsampleLike layer
            upsample_like_layer = layers.UpsampleLike(
                data_format='channels_first')

            # create input source
            source = np.zeros((1, 1, 2, 2), dtype=K.floatx())
            source = K.variable(source)
            target = np.zeros((1, 1, 5, 5), dtype=K.floatx())
            expected = target
            target = K.variable(target)

            # compute output
            computed_shape = upsample_like_layer.compute_output_shape(
                [source.shape, target.shape])
            actual = upsample_like_layer.call([source, target])
            actual = K.get_value(actual)

            self.assertEqual(actual.shape, computed_shape)
            self.assertAllEqual(actual, expected)
Exemplo n.º 2
0
    def test_mini_batch(self):
        # create simple UpsampleLike layer
        upsample_like_layer = layers.UpsampleLike()

        # create input source
        source = np.zeros((2, 2, 2, 1), dtype=K.floatx())
        source = K.variable(source)

        target = np.zeros((2, 5, 5, 1), dtype=K.floatx())
        expected = target
        target = K.variable(target)

        # compute output
        actual = upsample_like_layer.call([source, target])
        actual = K.get_value(actual)

        self.assertAllEqual(actual, expected)