test_detection_output_op.py 2.6 KB
Newer Older
D
dzhwinter 已提交
1
#   Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserve.
D
dzhwinter 已提交
2
#
D
dzhwinter 已提交
3 4 5
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
D
dzhwinter 已提交
6
#
D
dzhwinter 已提交
7
#     http://www.apache.org/licenses/LICENSE-2.0
D
dzhwinter 已提交
8
#
D
dzhwinter 已提交
9 10 11 12 13 14
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

15 16 17 18 19 20 21 22 23 24
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 已提交
25 26
        #loc.shape ((1, 4, 4, 1, 1))
        #conf.shape ((1, 4, 2, 1, 1))
27 28 29 30 31

        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 已提交
32 33 34 35 36 37 38 39 40 41 42
        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
        ])
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
        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__':
71 72 73
    # FIXME: detection_output_op will be rewritten. This unittest should be
    # enabled after rewriting.
    exit(0)  # temporary disable this unittest