test_detection_output_op.py 1.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
import unittest
import numpy as np
from op_test import OpTest


class TestUnpoolOp(OpTest):
    def setUp(self):
        self.op_type = "detection_output"
        self.init_test_case()

S
sweetsky0901 已提交
11 12
        #loc.shape ((1, 4, 4, 1, 1))
        #conf.shape ((1, 4, 2, 1, 1))
13 14 15 16 17

        loc = np.array([[[[[0.1]], [[0.1]], [[0.1]], [[0.1]]],
                         [[[0.1]], [[0.1]], [[0.1]], [[0.1]]],
                         [[[0.1]], [[0.1]], [[0.1]], [[0.1]]],
                         [[[0.1]], [[0.1]], [[0.1]], [[0.1]]]]])
S
sweetsky0901 已提交
18 19 20 21 22 23 24 25 26 27 28
        conf = np.array([[[[[0.1]], [[0.9]]], [[[0.2]], [[0.8]]],
                          [[[0.3]], [[0.7]]], [[[0.4]], [[0.6]]]]])
        priorbox = np.array([
            0.1, 0.1, 0.5, 0.5, 0.1, 0.1, 0.2, 0.2, 0.2, 0.2, 0.6, 0.6, 0.1,
            0.1, 0.2, 0.2, 0.3, 0.3, 0.7, 0.7, 0.1, 0.1, 0.2, 0.2, 0.4, 0.4,
            0.8, 0.8, 0.1, 0.1, 0.2, 0.2
        ])

        output = np.array([
            0, 1, 0.68997443, 0.099959746, 0.099959746, 0.50804031, 0.50804031
        ])
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
        self.inputs = {
            'Loc': loc.astype('float32'),
            'Conf': conf.astype('float32'),
            'PriorBox': priorbox.astype('float32')
        }
        self.attrs = {
            'num_classes': self.num_classes,
            'top_k': self.top_k,
            'nms_top_k': self.nms_top_k,
            'background_label_id': self.background_label_id,
            'nms_threshold': self.nms_threshold,
            'confidence_threshold': self.confidence_threshold,
        }
        self.outputs = {'Out': output.astype('float32')}

    def test_check_output(self):
        self.check_output()

    def init_test_case(self):
        self.num_classes = 2
        self.top_k = 10
        self.nms_top_k = 20
        self.background_label_id = 0
        self.nms_threshold = 0.01
        self.confidence_threshold = 0.01


if __name__ == '__main__':
    unittest.main()