2 Copyright (c) 2019 Intel Corporation
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
20 from accuracy_checker.adapters import SSDAdapter, Adapter
21 from accuracy_checker.config import ConfigError
22 from .common import make_representation
25 def test_detection_adapter():
27 'detection_out': np.array([[[[0, 3, 0.2, 0, 0, 1, 1], [0, 2, 0.5, 4, 4, 7, 7], [0, 5, 0.7, 3, 3, 9, 8]]]])
29 expected = make_representation('0.2,3,0,0,1,1;0.5,2,4,4,7,7;0.7,5,3,3,9,8')
31 actual = SSDAdapter({}, output_blob='detection_out')([raw], ['0'])
33 assert np.array_equal(actual, expected)
36 def test_detection_adapter_partially_filling_output_blob():
38 'detection_out': np.array(
39 [[[[0, 3, 0.2, 0, 0, 1, 1], [0, 2, 0.5, 4, 4, 7, 7], [0, 5, 0.7, 3, 3, 9, 8], [-1, 0, 0, 0, 0, 0, 0]]]]
42 expected = make_representation('0.2,3,0,0,1,1;0.5,2,4,4,7,7;0.7,5,3,3,9,8')
44 actual = SSDAdapter({}, output_blob='detection_out')([raw], ['0'])
46 assert np.array_equal(actual, expected)
49 def test_detection_adapter_partially_filling_output_blob_with_zeros_at_the_end():
51 'detection_out': np.array([[[
52 [0, 3, 0.2, 0, 0, 1, 1],
53 [0, 2, 0.5, 4, 4, 7, 7],
54 [0, 5, 0.7, 3, 3, 9, 8],
55 [-1, 0, 0, 0, 0, 0, 0],
59 expected = make_representation('0.2,3,0,0,1,1;0.5,2,4,4,7,7;0.7,5,3,3,9,8')
61 actual = SSDAdapter({}, output_blob='detection_out')([raw], ['0'])
63 assert np.array_equal(actual, expected)
66 def test_detection_adapter_batch_2():
68 'detection_out': np.array([[[[0, 3, 0.2, 0, 0, 1, 1], [0, 2, 0.5, 4, 4, 7, 7], [1, 5, 0.7, 3, 3, 9, 8]]]])
70 expected = make_representation(['0.2,3,0,0,1,1;0.5,2,4,4,7,7', '0.7,5,3,3,9,8'])
72 actual = SSDAdapter({}, output_blob='detection_out')([raw], ['0', '1'])
74 assert np.array_equal(actual, expected)
77 def test_dictionary_adapter_no_raise_warning_on_specific_args():
78 adapter_config = {'type': 'age_gender', 'gender_out': 'gender', 'age_out': 'age'}
79 with pytest.warns(None) as record:
80 Adapter.provide('age_gender', adapter_config)
81 assert len(record) == 0
84 def test_age_gender_adapter_raise_config_error_on_extra_args():
85 adapter_config = {'type': 'age_gender', 'gender_out': 'gender', 'age_out': 'age', 'something_extra': 'extra'}
86 with pytest.raises(ConfigError):
87 Adapter.provide('age_gender', adapter_config)
90 def test_face_person_detection_adapter_raise_config_error_on_extra_args():
92 'type': 'face_person_detection',
93 'face_detection_out': 'face',
94 'person_detection_out': 'person',
95 'something_extra': 'extra'
97 with pytest.raises(ConfigError):
98 Adapter.provide('face_person_detection', adapter_config)
101 def test_head_pose_adapter_raise_config_error_on_extra_args():
105 'angle_pitch': 'pitch',
106 'angle_roll': 'roll',
107 'something_extra': 'extra'
109 with pytest.raises(ConfigError):
110 Adapter.provide('head_pose', adapter_config)
113 def test_vehicle_attributes_adapter_raise_config_error_on_extra_args():
115 'type': 'vehicle_attributes',
116 'color_out': 'color',
118 'something_extra': 'extra'
120 with pytest.raises(ConfigError):
121 Adapter.provide('vehicle_attributes', adapter_config)