Exemple #1
0
    def test_invalid_input(self):
        bad_mean = 'invalid_data_type'
        bad_std = 'invalid_data_type'

        with self.assertRaises(ValueError):
            layers.RegressBoxes(mean=bad_mean, std=None)
        with self.assertRaises(ValueError):
            layers.RegressBoxes(mean=None, std=bad_std)
Exemple #2
0
    def test_simple(self):
        # create simple RegressBoxes layer
        layer = layers.RegressBoxes()

        # create input
        anchors = np.array([[
            [0, 0, 10, 10],
            [50, 50, 100, 100],
            [20, 20, 40, 40],
        ]], dtype=K.floatx())
        anchors = K.variable(anchors)

        regression = np.array([[
            [0, 0, 0, 0],
            [0.1, 0.1, 0, 0],
            [0, 0, 0.1, 0.1],
        ]], dtype=K.floatx())
        regression = K.variable(regression)

        # compute output
        computed_shape = layer.compute_output_shape(
            [anchors.shape, regression.shape])
        actual = layer.call([anchors, regression])
        actual = K.get_value(actual)

        self.assertEqual(actual.shape, computed_shape)

        # compute expected output
        expected = np.array([[
            [0, 0, 10, 10],
            [51, 51, 100, 100],
            [20, 20, 40.4, 40.4],
        ]], dtype=K.floatx())

        self.assertAllClose(actual, expected)
Exemple #3
0
    def test_mini_batch(self):
        mean = [0, 0, 0, 0]
        std = [0.2, 0.2, 0.2, 0.2]

        # create simple RegressBoxes layer
        layer = layers.RegressBoxes(mean=mean, std=std)

        # create input
        anchors = np.array([
            [
                [0, 0, 10, 10],  # 1
                [50, 50, 100, 100],  # 2
                [20, 20, 40, 40],  # 3
            ],
            [
                [20, 20, 40, 40],  # 3
                [0, 0, 10, 10],  # 1
                [50, 50, 100, 100],  # 2
            ],
        ], dtype=K.floatx())
        anchors = K.variable(anchors)

        regression = np.array([
            [
                [0, 0, 0, 0],  # 1
                [0.1, 0.1, 0, 0],  # 2
                [0, 0, 0.1, 0.1],  # 3
            ],
            [
                [0, 0, 0.1, 0.1],  # 3
                [0, 0, 0, 0],  # 1
                [0.1, 0.1, 0, 0],  # 2
            ],
        ], dtype=K.floatx())
        regression = K.variable(regression)

        # compute output
        actual = layer.call([anchors, regression])
        actual = K.get_value(actual)

        # compute expected output
        expected = np.array([
            [
                [0, 0, 10, 10],  # 1
                [51, 51, 100, 100],  # 2
                [20, 20, 40.4, 40.4],  # 3
            ],
            [
                [20, 20, 40.4, 40.4],  # 3
                [0, 0, 10, 10],  # 1
                [51, 51, 100, 100],  # 2
            ],
        ], dtype=K.floatx())

        self.assertAllClose(actual, expected)