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.
21 pytest.importorskip('accuracy_checker.launcher.dlsdk_launcher')
26 from pathlib import Path
27 from unittest.mock import PropertyMock
28 from accuracy_checker.config import ConfigError
29 from accuracy_checker.launcher import DLSDKLauncher
30 from accuracy_checker.launcher.dlsdk_launcher import DLSDKLauncherConfig
31 from accuracy_checker.launcher.launcher import create_launcher
32 from tests.common import update_dict
33 from accuracy_checker.dataset import DataRepresentation
34 from accuracy_checker.utils import contains_all
38 def mock_inference_engine(mocker):
40 mocker.patch('openvino.inference_engine.IEPlugin')
41 mocker.patch('openvino.inference_engine.IENetwork')
43 mocker.patch('inference_engine.IEPlugin')
44 mocker.patch('inference_engine.IENetwork')
48 def mock_inputs(mocker):
50 'accuracy_checker.launcher.input_feeder.InputFeeder._parse_inputs_config', return_value=({}, ['data'], None)
54 def get_dlsdk_test_model(models_dir, config_update=None):
57 'weights': str(models_dir / 'SampLeNet.bin'),
58 'model': str(models_dir / 'SampLeNet.xml'),
60 'adapter': 'classification',
61 '_models_prefix': str(models_dir)
64 config.update(config_update)
66 return create_launcher(config)
69 def get_image(image_path, input_shape):
71 img_raw = cv2.imread(str(image_path))
73 return DataRepresentation(cv2.resize(img_raw, (w, h)))
76 class TestDLSDKLauncherInfer:
77 def test_infer(self, data_dir, models_dir):
78 dlsdk_test_model = get_dlsdk_test_model(models_dir)
79 result = dlsdk_test_model.predict(['1.jpg'], [get_image(data_dir / '1.jpg', dlsdk_test_model.inputs['data'])])
81 assert dlsdk_test_model.adapter.output_blob == 'fc3'
82 assert result[0].label == 6
84 def test_launcher_creates(self, models_dir):
85 assert get_dlsdk_test_model(models_dir).inputs['data'] == [3, 32, 32]
87 def test_infer_with_additional_outputs(self, data_dir, models_dir):
88 dlsdk_test_model = get_dlsdk_test_model(models_dir, {'outputs': ['fc1', 'fc2']})
89 result = dlsdk_test_model.predict(['1.jpg'], [get_image(data_dir / '1.jpg', dlsdk_test_model.inputs['data'])])
90 outputs = list(dlsdk_test_model.network.outputs.keys())
91 adapter_output_blob = dlsdk_test_model.adapter.output_blob
93 assert contains_all(outputs, ['fc1', 'fc2', 'fc3'])
94 assert adapter_output_blob == 'fc3'
95 assert result[0].label == 6
97 def test_dlsdk_launcher_provide_input_shape_to_adapter(self, mocker, models_dir):
100 def raw_results_callback(outputs):
101 raw_results.update(outputs)
103 launcher = get_dlsdk_test_model(models_dir)
105 adapter_mock = mocker.patch('accuracy_checker.adapters.ClassificationAdapter.process')
106 launcher.predict(['1.png'], [DataRepresentation(np.zeros((32, 32, 3)))], output_callback=raw_results_callback)
107 adapter_mock.assert_called_once_with([raw_results], ['1.png'], [{'input_shape': {'data': [3, 32, 32]}, 'image_size': (32, 32, 3)}])
109 def test_dlsd_launcher_set_batch_size(self, models_dir):
110 dlsdk_test_model = get_dlsdk_test_model(models_dir, {'batch': 2})
111 assert dlsdk_test_model.batch == 2
114 @pytest.mark.usefixtures('mock_path_exists')
115 class TestDLSDKLauncherAffinity:
116 def test_dlsdk_launcher_valid_affinity_map(self, mocker, models_dir):
117 affinity_map = {'conv1' : 'GPU'}
120 'accuracy_checker.launcher.dlsdk_launcher.read_yaml', return_value=affinity_map
123 dlsdk_test_model = get_dlsdk_test_model(models_dir, {'device' : 'HETERO:CPU,GPU', 'affinity_map' : './affinity_map.yml'})
124 layers = dlsdk_test_model.network.layers
125 for key, value in affinity_map.items():
126 assert layers[key].affinity == value
128 def test_dlsdk_launcher_affinity_map_invalid_device(self, mocker, models_dir):
129 affinity_map = {'conv1' : 'GPU'}
132 'accuracy_checker.launcher.dlsdk_launcher.read_yaml', return_value=affinity_map
135 with pytest.raises(ConfigError):
136 get_dlsdk_test_model(models_dir, {'device' : 'HETERO:CPU,CPU', 'affinity_map' : './affinity_map.yml'})
138 def test_dlsdk_launcher_affinity_map_invalid_layer(self, mocker, models_dir):
139 affinity_map = {'none-existing-layer' : 'CPU'}
142 'accuracy_checker.launcher.dlsdk_launcher.read_yaml', return_value=affinity_map
145 with pytest.raises(ConfigError):
146 get_dlsdk_test_model(models_dir, {'device' : 'HETERO:CPU,CPU', 'affinity_map' : './affinity_map.yml'})
149 @pytest.mark.usefixtures('mock_path_exists', 'mock_inference_engine', 'mock_inputs')
150 class TestDLSDKLauncher:
151 def test_program_bitsream_when_device_is_fpga(self, mocker):
152 subprocess_mock = mocker.patch('subprocess.run')
154 'framework': 'dlsdk',
155 'weights': 'custom_weights',
156 'model': 'custom_model',
158 'bitstream': Path('custom_bitstream'),
159 'adapter': 'classification',
160 '_models_prefix': 'prefix',
161 '_aocl': Path('aocl')
163 launcher = create_launcher(config, {'label_map': {}})
164 subprocess_mock.assert_called_once_with(['aocl', 'program', 'acl0', 'custom_bitstream'])
167 def test_program_bitsream_when_fpga_in_hetero_device(self, mocker):
168 subprocess_mock = mocker.patch('subprocess.run')
170 'framework': 'dlsdk',
171 'weights': 'custom_weights',
172 'model': 'custom_model',
173 'device': 'hetero:fpga,cpu',
174 'bitstream': Path('custom_bitstream'),
175 'adapter': 'classification',
176 '_models_prefix': 'prefix',
177 '_aocl': Path('aocl')
179 launcher = create_launcher(config, {'label_map': {}})
180 subprocess_mock.assert_called_once_with(['aocl', 'program', 'acl0', 'custom_bitstream'])
183 def test_does_not_program_bitsream_when_device_is_not_fpga(self, mocker):
184 subprocess_mock = mocker.patch('subprocess.run')
186 'framework': 'dlsdk',
187 'weights': 'custom_weights',
188 'model': 'custom_model',
190 'bitstream': Path('custom_bitstream'),
191 'adapter': 'classification',
192 '_models_prefix': 'prefix',
193 '_aocl': Path('aocl')
195 create_launcher(config)
196 subprocess_mock.assert_not_called()
198 def test_does_not_program_bitsream_when_hetero_without_fpga(self, mocker):
199 subprocess_mock = mocker.patch('subprocess.run')
202 'framework': 'dlsdk',
203 'weights': 'custom_weights',
204 'model': 'custom_model',
205 'device': 'hetero:cpu,cpu',
206 'bitstream': Path('custom_bitstream'),
207 'adapter': 'classification',
208 '_models_prefix': 'prefix',
209 '_aocl': Path('aocl')
211 create_launcher(config)
212 subprocess_mock.assert_not_called()
214 def test_does_not_program_bitstream_if_compiler_mode_3_in_env_when_fpga_in_hetero_device(self, mocker):
215 subprocess_mock = mocker.patch('subprocess.run')
216 mocker.patch('os.environ.get', return_value='3')
219 'framework': 'dlsdk',
220 'weights': 'custom_weights',
221 'model': 'custom_model',
222 'device': 'hetero:fpga,cpu',
223 'bitstream': Path('custom_bitstream'),
224 'adapter': 'classification',
225 '_models_prefix': 'prefix',
226 '_aocl': Path('aocl')
228 create_launcher(config)
230 subprocess_mock.assert_not_called()
232 def test_does_not_program_bitstream_if_compiler_mode_3_in_env_when_fpga_in_device(self, mocker):
233 subprocess_mock = mocker.patch('subprocess.run')
234 mocker.patch('os.environ.get', return_value='3')
237 'framework': 'dlsdk',
238 'weights': 'custom_weights',
239 'model': 'custom_model',
241 'bitstream': Path('custom_bitstream'),
242 'adapter': 'classification',
243 '_models_prefix': 'prefix',
244 '_aocl': Path('aocl')
246 create_launcher(config)
248 subprocess_mock.assert_not_called()
250 def test_sets_dla_aocx_when_device_is_fpga(self, mocker):
251 mocker.patch('os.environ')
254 'framework': 'dlsdk',
255 'weights': 'custom_weights',
256 'model': 'custom_model',
258 'bitstream': Path('custom_bitstream'),
259 'adapter': 'classification',
260 '_models_prefix': 'prefix'
262 create_launcher(config, {'label_map': {}})
264 os.environ.__setitem__.assert_called_once_with('DLA_AOCX', 'custom_bitstream')
266 def test_sets_dla_aocx_when_fpga_in_hetero_device(self, mocker):
267 mocker.patch('os.environ')
270 'framework': 'dlsdk',
271 'weights': 'custom_weights',
272 'model': 'custom_model',
273 'device': 'hetero:fpga,cpu',
274 'bitstream': Path('custom_bitstream'),
275 'adapter': 'classification',
276 '_models_prefix': 'prefix'
278 create_launcher(config, {'label_map': {}})
279 os.environ.__setitem__.assert_called_once_with('DLA_AOCX', 'custom_bitstream')
281 def test_does_not_set_dla_aocx_when_device_is_not_fpga(self, mocker):
282 mocker.patch('os.environ')
285 'framework': 'dlsdk',
286 'weights': 'custom_weights',
287 'model': 'custom_model',
289 'bitstream': 'custom_bitstream',
290 'adapter': 'classification',
291 '_models_prefix': 'prefix'
293 create_launcher(config)
295 os.environ.__setitem__.assert_not_called()
297 def test_does_not_set_dla_aocx_when_hetero_without_fpga(self, mocker):
298 mocker.patch('os.environ')
301 'framework': 'dlsdk',
302 'weights': 'custom_weights',
303 'model': 'custom_model',
304 'device': 'hetero:cpu,cpu',
305 'bitstream': 'custom_bitstream',
306 'adapter': 'classification',
307 '_models_prefix': 'prefix'
309 create_launcher(config)
311 os.environ.__setitem__.assert_not_called()
313 def test_does_not_set_dla_aocx_if_compiler_mode_3_in_env_when_fpga_in_hetero_device(self, mocker):
314 mocker.patch('os.environ')
315 mocker.patch('os.environ.get', return_value='3')
318 'framework': 'dlsdk',
319 'weights': 'custom_weights',
320 'model': 'custom_model',
321 'device': 'hetero:fpga,cpu',
322 'bitstream': 'custom_bitstream',
323 'adapter': 'classification',
324 '_models_prefix': 'prefix'
326 create_launcher(config)
328 os.environ.__setitem__.assert_not_called()
330 def test_does_not_set_dla_aocx_if_compiler_mode_3_in_env_when_fpga_in_device(self, mocker):
331 mocker.patch('os.environ')
332 mocker.patch('os.environ.get', return_value='3')
335 'framework': 'dlsdk',
336 'weights': 'custom_weights',
337 'model': 'custom_model',
339 'bitstream': 'custom_bitstream',
340 'adapter': 'classification',
341 '_models_prefix': 'prefix'
343 create_launcher(config)
345 os.environ.__setitem__.assert_not_called()
347 def test_model_converted_from_caffe(self, mocker):
349 'accuracy_checker.launcher.dlsdk_launcher.convert_model',
350 return_value=('converted_model', 'converted_weights')
354 'framework': 'dlsdk',
355 'caffe_model': '/path/to/source_models/custom_model',
356 'caffe_weights': '/path/to/source_models/custom_weights',
358 'bitstream': Path('custom_bitstream'),
359 '_models_prefix': '/path/to/source_models',
360 'adapter': 'classification'
362 DLSDKLauncher(config, dummy_adapter)
364 mock.assert_called_once_with(
365 'custom_model', '/path/to/source_models/custom_model', '/path/to/source_models/custom_weights', 'caffe',
366 [], None, None, None, None
369 def test_model_converted_with_mo_params(self, mocker):
371 'accuracy_checker.launcher.dlsdk_launcher.convert_model',
372 return_value=('converted_model', 'converted_weights')
376 'framework': "dlsdk",
377 'caffe_model': '/path/to/source_models/custom_model',
378 'caffe_weights': '/path/to/source_models/custom_weights',
380 'bitstream': Path('custom_bitstream'),
381 '_models_prefix': '/path/to/source_models',
382 'mo_params': {'data_type': 'FP16'},
383 'adapter': 'classification'
385 DLSDKLauncher(config, dummy_adapter)
387 mock.assert_called_once_with(
388 'custom_model', '/path/to/source_models/custom_model', '/path/to/source_models/custom_weights', 'caffe',
389 [], {'data_type': 'FP16'}, None, None, None
392 def test_model_converted_with_mo_flags(self, mocker):
394 'accuracy_checker.launcher.dlsdk_launcher.convert_model',
395 return_value=('converted_model', 'converted_weights')
399 'framework': 'dlsdk',
400 'caffe_model': '/path/to/source_models/custom_model',
401 'caffe_weights': '/path/to/source_models/custom_weights',
403 'bitstream': Path('custom_bitstream'),
404 '_models_prefix': '/path/to/source_models',
405 'mo_flags': ['reverse_input_channels'],
406 'adapter': 'classification'
409 DLSDKLauncher(config, dummy_adapter)
411 mock.assert_called_once_with(
412 'custom_model', '/path/to/source_models/custom_model', '/path/to/source_models/custom_weights', 'caffe',
413 [], None, ['reverse_input_channels'], None, None
416 def test_model_converted_to_output_dir_in_mo_params(self, mocker):
418 'framework': 'dlsdk',
419 'tf_model': '/path/to/source_models/custom_model',
421 '_models_prefix': '/path/to',
422 'adapter': 'classification',
423 'mo_params': {'output_dir': '/path/to/output/models'}
425 mocker.patch('accuracy_checker.launcher.model_conversion.find_mo', return_value='ModelOptimizer')
426 prepare_args_patch = mocker.patch('accuracy_checker.launcher.model_conversion.prepare_args')
428 'input_model': '/path/to/source_models/custom_model',
429 'model_name': 'custom_model',
430 'output_dir': '/path/to/output/models',
435 'accuracy_checker.launcher.model_conversion.exec_mo_binary',
436 return_value=subprocess.CompletedProcess(args, returncode=0)
438 DLSDKLauncher(config, dummy_adapter)
439 prepare_args_patch.assert_called_once_with('ModelOptimizer', flag_options=[], value_options=args)
441 def test_model_converted_from_tf(self, mocker):
443 'accuracy_checker.launcher.dlsdk_launcher.convert_model',
444 return_value=('converted_model', 'converted_weights')
448 'framework': 'dlsdk',
449 'tf_model': '/path/to/source_models/custom_model',
451 '_models_prefix': '/path/to/source_models',
452 'adapter': 'classification'
454 DLSDKLauncher(config, dummy_adapter)
456 mock.assert_called_once_with(
457 'custom_model', '/path/to/source_models/custom_model', '', 'tf', [], None, None, None, None
460 def test_model_converted_from_tf_with_arg_path_to_custom_tf_config(self, mocker):
462 'framework': 'dlsdk',
463 'tf_model': '/path/to/source_models/custom_model',
465 '_models_prefix': '/path/to',
466 'adapter': 'classification',
467 'mo_params': {'tensorflow_use_custom_operations_config': 'ssd_v2_support.json'},
468 '_tf_custom_op_config_dir': 'config/dir'
470 mocker.patch('accuracy_checker.launcher.model_conversion.find_mo', return_value=Path('/path/ModelOptimizer'))
471 prepare_args_patch = mocker.patch('accuracy_checker.launcher.model_conversion.prepare_args')
474 'input_model': '/path/to/source_models/custom_model',
475 'model_name': 'custom_model',
477 'tensorflow_use_custom_operations_config': 'config/dir/ssd_v2_support.json'
481 'accuracy_checker.launcher.model_conversion.exec_mo_binary',
482 return_value=subprocess.CompletedProcess(args, returncode=0)
484 DLSDKLauncher(config, dummy_adapter)
485 prepare_args_patch.assert_called_once_with('/path/ModelOptimizer', flag_options=[], value_options=args)
487 def test_model_converted_from_tf_with_default_path_to_custom_tf_config(self, mocker):
489 'framework': 'dlsdk',
490 'tf_model': '/path/to/source_models/custom_model',
492 '_models_prefix': '/path/to',
493 'adapter': 'classification',
494 'mo_params': {'tensorflow_use_custom_operations_config': 'config.json'}
496 mocker.patch('accuracy_checker.launcher.model_conversion.find_mo', return_value=Path('/path/ModelOptimizer'))
497 prepare_args_patch = mocker.patch('accuracy_checker.launcher.model_conversion.prepare_args')
500 'input_model': '/path/to/source_models/custom_model',
501 'model_name': 'custom_model',
503 'tensorflow_use_custom_operations_config': '/path/extensions/front/tf/config.json'
507 'accuracy_checker.launcher.model_conversion.exec_mo_binary',
508 return_value=subprocess.CompletedProcess(args, returncode=0)
510 DLSDKLauncher(config, dummy_adapter)
511 prepare_args_patch.assert_called_once_with('/path/ModelOptimizer', flag_options=[], value_options=args)
513 def test_model_converted_from_tf_with_default_path_to_obj_detection_api_config(self, mocker):
515 'framework': 'dlsdk',
516 'tf_model': '/path/to/source_models/custom_model',
518 '_models_prefix': '/path/to',
519 'adapter': 'classification',
520 'mo_params': {'tensorflow_object_detection_api_pipeline_config': 'operations.config'},
521 '_tf_obj_detection_api_pipeline_config_path': None
523 mocker.patch('accuracy_checker.launcher.model_conversion.find_mo', return_value=Path('/path/ModelOptimizer'))
524 prepare_args_patch = mocker.patch('accuracy_checker.launcher.model_conversion.prepare_args')
527 'input_model': '/path/to/source_models/custom_model',
528 'model_name': 'custom_model',
530 'tensorflow_object_detection_api_pipeline_config': '/path/to/source_models/operations.config'
534 'accuracy_checker.launcher.model_conversion.exec_mo_binary',
535 return_value=subprocess.CompletedProcess(args, returncode=0)
537 DLSDKLauncher(config, dummy_adapter)
538 prepare_args_patch.assert_called_once_with('/path/ModelOptimizer', flag_options=[], value_options=args)
540 def test_model_converted_from_tf_with_arg_path_to_obj_detection_api_config(self, mocker):
542 'framework': 'dlsdk',
543 'tf_model': '/path/to/source_models/custom_model',
545 '_models_prefix': '/path/to',
546 'adapter': 'classification',
547 'mo_params': {'tensorflow_object_detection_api_pipeline_config': 'operations.config'},
548 '_tf_custom_op_config_dir': 'config/dir',
549 '_tf_obj_detection_api_pipeline_config_path': 'od_api'
551 mocker.patch('accuracy_checker.launcher.model_conversion.find_mo', return_value=Path('/path/ModelOptimizer'))
552 prepare_args_patch = mocker.patch('accuracy_checker.launcher.model_conversion.prepare_args')
555 'input_model': '/path/to/source_models/custom_model',
556 'model_name': 'custom_model',
558 'tensorflow_object_detection_api_pipeline_config': 'od_api/operations.config'
562 'accuracy_checker.launcher.model_conversion.exec_mo_binary',
563 return_value=subprocess.CompletedProcess(args, returncode=0)
565 DLSDKLauncher(config, dummy_adapter)
566 prepare_args_patch.assert_called_once_with('/path/ModelOptimizer', flag_options=[], value_options=args)
568 def test_model_converted_from_mxnet(self, mocker):
570 'accuracy_checker.launcher.dlsdk_launcher.convert_model',
571 return_value=('converted_model', 'converted_weights')
575 'framework': 'dlsdk',
576 'mxnet_weights': '/path/to/source_models/custom_weights',
578 '_models_prefix': '/path/to/source_models',
579 'adapter': 'classification'
581 DLSDKLauncher(config, dummy_adapter)
583 mock.assert_called_once_with(
584 'custom_weights', '', '/path/to/source_models/custom_weights', 'mxnet', [], None, None, None, None
587 def test_model_converted_from_onnx(self, mocker):
589 'accuracy_checker.launcher.dlsdk_launcher.convert_model',
590 return_value=('converted_model', 'converted_weights')
594 'framework': 'dlsdk',
595 'onnx_model': '/path/to/source_models/custom_model',
597 '_models_prefix': '/path/to/source_models',
598 'adapter': 'classification'
600 DLSDKLauncher(config, dummy_adapter)
602 mock.assert_called_once_with(
603 'custom_model', '/path/to/source_models/custom_model', '', 'onnx', [], None, None, None, None
606 def test_model_converted_from_kaldi(self, mocker):
608 'accuracy_checker.launcher.dlsdk_launcher.convert_model',
609 return_value=('converted_model', 'converted_weights')
613 'framework': 'dlsdk',
614 'kaldi_model': '/path/to/source_models/custom_model',
616 '_models_prefix': '/path/to/source_models',
617 'adapter': 'classification'
619 DLSDKLauncher(config, dummy_adapter)
621 mock.assert_called_once_with(
622 'custom_model', '/path/to/source_models/custom_model', '', 'kaldi', [], None, None, None, None
625 def test_raises_with_multiple_models_caffe_dlsdk(self):
627 'framework': 'dlsdk',
628 'caffe_model': 'caffe_model',
629 'caffe_weights': 'caffe_weights',
630 'model': 'custom_model',
631 'weights': 'custom_weights',
633 '_models_prefix': 'prefix'
636 with pytest.raises(ConfigError):
637 DLSDKLauncher(config, dummy_adapter)
639 def test_raises_with_multiple_models_tf_dlsdk(self):
641 'framework': 'dlsdk',
642 'tf_model': 'tf_model',
643 'model': 'custom_model',
644 'weights': 'custom_weights',
646 '_models_prefix': 'prefix'
649 with pytest.raises(ConfigError):
650 DLSDKLauncher(config, dummy_adapter)
652 def test_raises_with_multiple_models_mxnet_dlsdk(self):
654 'framework': 'dlsdk',
655 'mxnet_weights': 'mxnet_weights',
656 'model': 'custom_model',
657 'weights': 'custom_weights',
659 '_models_prefix': 'prefix'
662 with pytest.raises(ConfigError):
663 DLSDKLauncher(config, dummy_adapter)
665 def test_raises_with_multiple_models_onnx_dlsdk(self):
667 'framework': 'dlsdk',
668 'onnx_model': 'onnx_model',
669 'model': 'custom_model',
670 'weights': 'custom_weights',
672 '_models_prefix': 'prefix'
675 with pytest.raises(ConfigError):
676 DLSDKLauncher(config, dummy_adapter)
678 def test_raises_with_multiple_models_kaldi_dlsdk(self):
680 'framework': 'dlsdk',
681 'onnx_model': 'kaldi_model',
682 'model': 'custom_model',
683 'weights': 'custom_weights',
685 '_models_prefix': 'prefix'
688 with pytest.raises(ConfigError):
689 DLSDKLauncher(config, dummy_adapter)
691 def test_raises_with_multiple_models_mxnet_caffe(self):
693 'framework': 'dlsdk',
694 'mxnet_weights': 'mxnet_weights',
695 'caffe_model': 'caffe_model',
696 'caffe_weights': 'caffe_weights',
698 '_models_prefix': 'prefix'
701 with pytest.raises(ConfigError):
702 DLSDKLauncher(config, dummy_adapter)
704 def test_raises_with_multiple_models_tf_caffe(self):
707 'framework': 'dlsdk',
708 'tf_model': 'tf_model',
709 'caffe_model': 'caffe_model',
710 'caffe_weights': 'caffe_weights',
712 '_models_prefix': 'prefix'
715 with pytest.raises(ConfigError):
716 DLSDKLauncher(config, dummy_adapter)
718 def test_raises_with_multiple_models_onnx_caffe(self):
721 'framework': 'dlsdk',
722 'onnx_model': 'onnx_model',
723 'caffe_model': 'caffe_model',
724 'caffe_weights': 'caffe_weights',
726 '_models_prefix': 'prefix'
729 with pytest.raises(ConfigError):
730 DLSDKLauncher(config, dummy_adapter)
732 def test_raises_with_multiple_models_mxnet_tf(self):
734 'framework': 'dlsdk',
735 'mxnet_weights': 'mxnet_weights',
736 'tf_model': 'tf_model',
738 '_models_prefix': 'prefix'
741 with pytest.raises(ConfigError):
742 DLSDKLauncher(config, dummy_adapter)
744 def test_raises_with_multiple_models_onnx_tf(self):
746 'framework': 'dlsdk',
747 'onnx_model': 'onnx_model',
748 'tf_model': 'tf_model',
750 '_models_prefix': 'prefix'
753 with pytest.raises(ConfigError):
754 DLSDKLauncher(config, dummy_adapter)
756 def test_raises_with_multiple_models_mxnet_caffe_tf(self):
758 'framework': 'dlsdk',
759 'mxnet_weights': 'mxnet_weights',
760 'caffe_model': 'caffe_model',
761 'caffe_weights': 'caffe_weights',
762 'tf_model': 'tf_model',
764 '_models_prefix': 'prefix'
767 with pytest.raises(ConfigError):
768 DLSDKLauncher(config, dummy_adapter)
770 def test_raises_with_multiple_models_dlsdk_caffe_tf(self):
772 'framework': 'dlsdk',
773 'model': 'custom_model',
774 'weights': 'custom_weights',
775 'caffe_model': 'caffe_model',
776 'caffe_weights': 'caffe_weights',
777 'tf_model': 'tf_model',
779 '_models_prefix': 'prefix'
782 with pytest.raises(ConfigError):
783 DLSDKLauncher(config, dummy_adapter)
785 def test_raises_with_multiple_models_dlsdk_caffe_onnx(self):
787 'framework': 'dlsdk',
788 'model': 'custom_model',
789 'weights': 'custom_weights',
790 'caffe_model': 'caffe_model',
791 'caffe_weights': 'caffe_weights',
792 'onnx_model': 'onnx_model',
794 '_models_prefix': 'prefix'
797 with pytest.raises(ConfigError):
798 DLSDKLauncher(config, dummy_adapter)
800 def test_raises_with_multiple_models_dlsdk_caffe_mxnet(self):
802 'framework': 'dlsdk',
803 'model': 'custom_model',
804 'weights': 'custom_weights',
805 'caffe_model': 'caffe_model',
806 'caffe_weights': 'caffe_weights',
807 'mxnet_weights': 'mxnet_weights',
809 '_models_prefix': 'prefix'
812 with pytest.raises(ConfigError):
813 DLSDKLauncher(config, dummy_adapter)
815 def test_raises_with_multiple_models_dlsdk_tf_mxnet(self):
817 'framework': "dlsdk",
818 'model': 'custom_model',
819 'weights': 'custom_weights',
820 'mxnet_weights': 'mxnet_weights',
821 'tf_model': 'tf_model',
823 '_models_prefix': 'prefix'
826 with pytest.raises(ConfigError):
827 DLSDKLauncher(config, dummy_adapter)
829 def test_raises_with_multiple_models_dlsdk_tf_onnx(self):
831 'framework': 'dlsdk',
832 'model': 'custom_model',
833 'weights': 'custom_weights',
834 'onnx_model': 'onnx_model',
835 'tf_model': 'tf_model',
837 '_models_prefix': 'prefix'
840 with pytest.raises(ConfigError):
841 DLSDKLauncher(config, dummy_adapter)
843 def test_raises_with_multiple_models_dlsdk_tf_mxnet_caffe(self):
845 'framework': 'dlsdk',
846 'model': 'custom_model',
847 'weights': 'custom_weights',
848 'caffe_model': 'caffe_model',
849 'caffe_weights': 'caffe_weights',
850 'mxnet_weights': 'mxnet_weights',
851 'onnx_model': 'onnx_model',
852 'tf_model': 'tf_model',
854 '_models_prefix': 'prefix'
856 with pytest.raises(ConfigError):
857 DLSDKLauncher(config, dummy_adapter)
859 def test_raises_with_multiple_models_dlsdk_tf_mxnet_caffe_onnx(self):
861 'framework': 'dlsdk',
862 'model': 'custom_model',
863 'weights': 'custom_weights',
864 'caffe_model': 'caffe_model',
865 'caffe_weights': 'caffe_weights',
866 'mxnet_weights': 'mxnet_weights',
867 'tf_model': 'tf_model',
869 '_models_prefix': 'prefix'
872 with pytest.raises(ConfigError):
873 DLSDKLauncher(config, dummy_adapter)
876 @pytest.mark.usefixtures('mock_path_exists', 'mock_inputs', 'mock_inference_engine')
877 class TestDLSDKLauncherConfig:
881 'weights': 'foo.bin',
883 'framework': 'dlsdk',
884 'adapter': 'classification',
885 '_models_prefix': 'prefix'
887 self.config = DLSDKLauncherConfig('dlsdk_launcher')
889 def test_hetero_correct(self):
890 self.config.validate(update_dict(self.launcher, device='HETERO:CPU'))
891 self.config.validate(update_dict(self.launcher, device='HETERO:CPU,FPGA'))
893 def test_hetero_endswith_comma(self):
894 with pytest.raises(ConfigError):
895 self.config.validate(update_dict(self.launcher, device='HETERO:CPU,FPGA,'))
897 def test_normal_multiple_devices(self):
898 with pytest.raises(ConfigError):
899 self.config.validate(update_dict(self.launcher, device='CPU,FPGA'))
901 def test_hetero_empty(self):
902 with pytest.raises(ConfigError):
903 self.config.validate(update_dict(self.launcher, device='HETERO:'))
905 def test_normal(self):
906 self.config.validate(update_dict(self.launcher, device='CPU'))
908 def test_missed_model_in_create_dlsdk_launcher_raises_config_error_exception(self):
909 config = {'framework': 'dlsdk', 'weights': 'custom', 'adapter': 'classification', 'device': 'cpu'}
911 with pytest.raises(ConfigError):
912 create_launcher(config)
914 def test_missed_weights_in_create_dlsdk_launcher_raises_config_error_exception(self):
915 launcher = {'framework': 'dlsdk', 'model': 'custom', 'adapter': 'ssd', 'device': 'cpu'}
917 with pytest.raises(ConfigError):
918 create_launcher(launcher)
920 def test_missed_adapter_in_create_dlsdk_launcher_raises_config_error_exception(self):
921 launcher_config = {'framework': 'dlsdk', 'model': 'custom', 'weights': 'custom'}
923 with pytest.raises(ConfigError):
924 create_launcher(launcher_config)
926 def test_undefined_str_adapter_in_create_dlsdk_launcher_raises_config_error_exception(self):
927 launcher_config = {'framework': 'dlsdk', 'model': 'custom', 'weights': 'custom', 'adapter': 'undefined_str'}
929 with pytest.raises(ConfigError):
930 create_launcher(launcher_config)
932 def test_empty_dir_adapter_in_create_dlsdk_launcher_raises_config_error_exception(self):
933 launcher_config = {'framework': 'dlsdk', 'model': 'custom', 'weights': 'custom', 'adapter': {}}
935 with pytest.raises(ConfigError):
936 create_launcher(launcher_config)
938 def test_missed_type_in_dir_adapter_in_create_dlsdk_launcher_raises_config_error_exception(self):
939 launcher_config = {'framework': 'dlsdk', 'model': 'custom', 'weights': 'custom', 'adapter': {'key': 'val'}}
941 with pytest.raises(ConfigError):
942 create_launcher(launcher_config)
944 def test_undefined_type_in_dir_adapter_in_create_dlsdk_launcher_raises_config_error_exception(self):
946 'framework': 'dlsdk',
949 'adapter': {'type': 'undefined'}
952 with pytest.raises(ConfigError):
953 create_launcher(launcher_config)
955 def test_dlsdk_launcher(self):
957 'framework': 'dlsdk', 'model': 'custom', 'weights': 'custom', 'adapter': 'ssd', 'device': 'cpu',
958 '_models_prefix': 'models'
960 create_launcher(launcher)
962 def test_dlsdk_launcher_model_with_several_image_inputs_raise_value_error(self, mocker):
963 launcher_config = {'framework': 'dlsdk', 'model': 'custom', 'weights': 'custom', 'adapter': {'key': 'val'}}
965 with pytest.raises(ValueError):
967 'accuracy_checker.launcher.dlsdk_launcher.DLSDKLauncher.inputs',
968 new_callable=PropertyMock(return_value={'data1': [3, 227, 227], 'data2': [3, 227, 227]})
970 create_launcher(launcher_config)
972 def test_dlsdk_launcher_model_no_image_inputs_raise_value_error(self):
973 launcher_config = {'framework': 'dlsdk', 'model': 'custom', 'weights': 'custom', 'adapter': {'key': 'val'}}
975 with pytest.raises(ValueError):
976 create_launcher(launcher_config)