def test_raises_with_multiple_models_kaldi_dlsdk(self):
        config = {
            'framework': 'dlsdk',
            'onnx_model': 'kaldi_model',
            'model': 'custom_model',
            'weights': 'custom_weights',
            'device': 'cpu',
        }

        with pytest.raises(ConfigError):
            DLSDKLauncher(config)
    def test_raises_with_multiple_models_onnx_tf(self):
        config = {
            "framework": "dlsdk",
            "onnx_model": 'onnx_model',
            "tf_model": 'tf_model',
            "device": 'cpu',
            "bitstream": "custom_bitstream"
        }

        with pytest.raises(ValueError):
            DLSDKLauncher(config, dummy_adapter)
Esempio n. 3
0
    def test_raises_with_multiple_models_mxnet_tf(self):
        config = {
            'framework': 'dlsdk',
            'mxnet_weights': 'mxnet_weights',
            'tf_model': 'tf_model',
            'device': 'cpu',
            '_models_prefix': 'prefix'
        }

        with pytest.raises(ConfigError):
            DLSDKLauncher(config, dummy_adapter)
Esempio n. 4
0
 def setup(self):
     self.launcher = {
         'model': 'foo.xml',
         'weights': 'foo.bin',
         'device': 'CPU',
         'framework': 'dlsdk',
         'adapter': 'classification',
         '_models_prefix': 'prefix'
     }
     self.config = DLSDKLauncherConfigValidator(
         'dlsdk_launcher', fields=DLSDKLauncher.parameters())
Esempio n. 5
0
    def test_raises_with_multiple_models_onnx_tf(self):
        config = {
            'framework': 'dlsdk',
            'onnx_model': 'onnx_model',
            'tf_model': 'tf_model',
            'device': 'cpu',
            '_models_prefix': 'prefix'
        }

        with pytest.raises(ConfigError):
            DLSDKLauncher(config)
Esempio n. 6
0
    def test_raises_with_multiple_models_mxnet_caffe(self):
        config = {
            'framework': 'dlsdk',
            'mxnet_weights': 'mxnet_weights',
            'caffe_model': 'caffe_model',
            'caffe_weights': 'caffe_weights',
            'device': 'cpu',
        }

        with pytest.raises(ConfigError):
            DLSDKLauncher(config)
    def test_raises_with_multiple_models_dlsdk_tf_mxnet(self):
        config = {
            'framework': "dlsdk",
            'model': 'custom_model',
            'weights': 'custom_weights',
            'mxnet_weights': 'mxnet_weights',
            'tf_model': 'tf_model',
            'device': 'cpu',
        }

        with pytest.raises(ConfigError):
            DLSDKLauncher(config)
Esempio n. 8
0
    def test_raises_with_multiple_models_mxnet_dlsdk(self):
        config = {
            'framework': 'dlsdk',
            'mxnet_weights': 'mxnet_weights',
            'model': 'custom_model',
            'weights': 'custom_weights',
            'device': 'cpu',
            '_models_prefix': 'prefix'
        }

        with pytest.raises(ConfigError):
            DLSDKLauncher(config)
    def test_raises_with_multiple_models_kaldi_dlsdk(self):
        config = {
            "framework": "dlsdk",
            "onnx_model": 'kaldi_model',
            "model": 'custom_model',
            "weights": 'custom_weights',
            "device": 'cpu',
            "bitstream": "custom_bitstream"
        }

        with pytest.raises(ValueError):
            DLSDKLauncher(config, dummy_adapter)
    def test_raises_with_multiple_models_mxnet_caffe(self):
        config = {
            "framework": "dlsdk",
            "mxnet_weights": 'mxnet_weights',
            "caffe_model": 'caffe_model',
            "caffe_weights": 'caffe_weights',
            "device": 'cpu',
            "bitstream": "custom_bitstream"
        }

        with pytest.raises(ValueError):
            DLSDKLauncher(config, dummy_adapter)
Esempio n. 11
0
    def test_raises_with_multiple_models_onnx_caffe(self, mocker):
        mock_inference_engine(mocker)

        config = {
            "framework": "dlsdk",
            "onnx_model": 'onnx_model',
            "caffe_model": 'caffe_model',
            "caffe_weights": 'caffe_weights',
            "device": 'cpu',
            "bitstream": "custom_bitstream"
        }

        with pytest.raises(ValueError):
            DLSDKLauncher(config, dummy_adapter)
Esempio n. 12
0
    def test_raises_with_multiple_models_dlsdk_caffe_onnx(self):
        config = {
            'framework': 'dlsdk',
            'model': 'custom_model',
            'weights': 'custom_weights',
            'caffe_model': 'caffe_model',
            'caffe_weights': 'caffe_weights',
            'onnx_model': 'onnx_model',
            'device': 'cpu',
            '_models_prefix': 'prefix'
        }

        with pytest.raises(ConfigError):
            DLSDKLauncher(config, dummy_adapter)
    def test_raises_with_tf_model_and_tf_meta_both_provided(self):
        config = {
            'framework': 'dlsdk',
            'model': 'custom_model',
            'weights': 'custom_weights',
            'caffe_model': 'caffe_model',
            'caffe_weights': 'caffe_weights',
            'mxnet_weights': 'mxnet_weights',
            'tf_model': 'tf_model',
            'tf_meta': 'tf_meta',
            'device': 'cpu',
        }

        with pytest.raises(ConfigError):
            DLSDKLauncher(config)
Esempio n. 14
0
    def test_model_converted_from_kaldi(self, mocker):
        mock = mocker.patch(
            'accuracy_checker.launcher.dlsdk_launcher.convert_model',
            return_value=('converted_model', 'converted_weights'))

        config = {
            'framework': 'dlsdk',
            'kaldi_model': '/path/to/source_models/custom_model',
            'device': 'cpu',
            '_models_prefix': '/path/to/source_models',
            'adapter': 'classification'
        }
        DLSDKLauncher(config, dummy_adapter)

        mock.assert_called_once_with('custom_model',
                                     '/path/to/source_models/custom_model', '',
                                     'kaldi', [], None, None, None, None)
    def test_model_conversion_raises_config_error_if_output_dir_in_mo_params_and_converted_model_dir_both_provided(
            self, mocker):
        config = {
            "framework": "dlsdk",
            "tf_model": '/path/to/source_models/custom_model',
            "device": 'cpu',
            "_converted_models": Path("/path/to/converted_models"),
            "_models_prefix": Path("/path/to"),
            "adapter": "classification",
            'converted_model_dir': 'models',
            'mo_params': {
                'output_dir': Path('/path/to/output/models')
            }
        }
        mocker.patch('pathlib.Path.resolve',
                     return_value=Path(config['_converted_models']))

        with pytest.raises(ConfigError):
            DLSDKLauncher(config, dummy_adapter)
    def test_model_converted_from_kaldi(self, mocker):
        mock = mocker.patch(
            'accuracy_checker.launcher.dlsdk_launcher.convert_model',
            return_value=('converted_model', 'converted_weights')
        )

        config = {
            'framework': 'dlsdk',
            'kaldi_model': '/path/to/source_models/custom_model',
            'device': 'cpu',
            'adapter': 'classification',
            'should_log_cmd': False
        }
        DLSDKLauncher(config)

        mock.assert_called_once_with(
            'custom_model', '/path/to/source_models/custom_model', '', '',
            FrameworkParameters('kaldi', False), [], None, None, None, None, None,
            should_log_cmd=False
        )
Esempio n. 17
0
    def test_model_converted_from_mxnet(self, mocker):
        mock = mocker.patch(
            'accuracy_checker.launcher.dlsdk_launcher.convert_model',
            return_value=('converted_model',
                          'converted_weights'))  # type: MagicMock

        config = {
            "framework": "dlsdk",
            "mxnet_weights": '/path/to/source_models/custom_weights',
            "device": 'cpu',
            "bitstream": "custom_bitstream",
            "_converted_models": Path("/path/to/converted_models"),
            "_models_prefix": Path("/path/to/source_models"),
            "adapter": "classification"
        }
        mock_inputs(mocker)
        DLSDKLauncher(config, dummy_adapter)

        mock.assert_called_once_with(
            'custom_weights', Path("/path/to/converted_models"), None,
            Path("/path/to/source_models/custom_weights"), 'mxnet', [], None)
Esempio n. 18
0
    def test_model_converted_from_tf_checkpoint_with_arg_path_to_obj_detection_api_config(
            self, mocker):
        config = {
            'framework': 'dlsdk',
            'tf_meta': '/path/to/source_models/custom_model',
            'device': 'cpu',
            '_models_prefix': '/path/to',
            'adapter': 'classification',
            'mo_params': {
                'tensorflow_object_detection_api_pipeline_config':
                'operations.config'
            },
            '_tf_custom_op_config_dir': 'config/dir',
            '_tf_obj_detection_api_pipeline_config_path': 'od_api'
        }
        mocker.patch('accuracy_checker.launcher.model_conversion.find_mo',
                     return_value=Path('/path/ModelOptimizer'))
        prepare_args_patch = mocker.patch(
            'accuracy_checker.launcher.model_conversion.prepare_args')

        args = {
            'input_meta_graph':
            '/path/to/source_models/custom_model',
            'model_name':
            'custom_model',
            'framework':
            'tf',
            'tensorflow_object_detection_api_pipeline_config':
            'od_api/operations.config'
        }

        mocker.patch(
            'accuracy_checker.launcher.model_conversion.exec_mo_binary',
            return_value=subprocess.CompletedProcess(args, returncode=0))
        DLSDKLauncher(config)
        prepare_args_patch.assert_called_once_with('/path/ModelOptimizer',
                                                   flag_options=[],
                                                   value_options=args)
    def test_model_converted_from_kaldi(self, mocker):
        mock = mocker.patch(
            'accuracy_checker.launcher.dlsdk_launcher.convert_model',
            return_value=('converted_model',
                          'converted_weights'))  # type: MagicMock

        config = {
            "framework": "dlsdk",
            "kaldi_model": '/path/to/source_models/custom_model',
            "device": 'cpu',
            "bitstream": "custom_bitstream",
            "_converted_models": Path("/path/to/converted_models"),
            "_models_prefix": Path("/path/to/source_models"),
            "adapter": "classification"
        }
        mocker.patch('pathlib.Path.resolve',
                     return_value=Path(config['_converted_models']))
        DLSDKLauncher(config, dummy_adapter)

        mock.assert_called_once_with(
            'custom_model', Path("/path/to/converted_models"),
            Path("/path/to/source_models/custom_model"), None, 'kaldi', [], {},
            [], None)
    def test_model_converted_to_output_dir_in_mo_params(self, mocker):
        config = {
            'framework': 'dlsdk',
            'tf_model': '/path/to/source_models/custom_model',
            'device': 'cpu',
            'adapter': 'classification',
            'mo_params': {'output_dir': '/path/to/output/models'}
        }
        mocker.patch('accuracy_checker.launcher.model_conversion.find_mo', return_value='ModelOptimizer')
        prepare_args_patch = mocker.patch('accuracy_checker.launcher.model_conversion.prepare_args')
        args = {
            'input_model': '/path/to/source_models/custom_model',
            'model_name': 'custom_model',
            'output_dir': '/path/to/output/models',
            'framework': 'tf'
        }

        mocker.patch(
            'accuracy_checker.launcher.model_conversion.exec_mo_binary',
            return_value=subprocess.CompletedProcess(args, returncode=0)
        )
        DLSDKLauncher(config)
        prepare_args_patch.assert_called_once_with('ModelOptimizer', flag_options=[], value_options=args)
    def test_model_converted_with_mo_params(self, mocker):
        mock = mocker.patch(
            'accuracy_checker.launcher.dlsdk_launcher.convert_model',
            return_value=('converted_model', 'converted_weights')
        )

        config = {
            'framework': "dlsdk",
            'caffe_model': '/path/to/source_models/custom_model',
            'caffe_weights': '/path/to/source_models/custom_weights',
            'device': 'cpu',
            'bitstream': Path('custom_bitstream'),
            'mo_params': {'data_type': 'FP16'},
            'adapter': 'classification',
            'should_log_cmd': False
        }
        DLSDKLauncher(config)

        mock.assert_called_once_with(
            'custom_model', '/path/to/source_models/custom_model', '/path/to/source_models/custom_weights', '',
            FrameworkParameters('caffe', False),
            [], {'data_type': 'FP16'}, None, None, None, None, should_log_cmd=False
        )
Esempio n. 22
0
    def test_not_converted_twice_from_tf_if_use_model_from_cache(self, mocker):
        mock = mocker.patch(
            'accuracy_checker.launcher.dlsdk_launcher.convert_model',
            return_value=('converted_model',
                          'converted_weights'))  # type: MagicMock
        mock_inputs(mocker)
        with mock_filesystem([
                'converted_models/bar/converted_model.bin',
                'converted_models/bar/converted_model.xml'
        ]) as prefix:
            config = {
                "framework": "dlsdk",
                "tf_model": '/source_models/bar/custom_model.frozen.pb',
                "device": 'cpu',
                "bitstream": "custom_bitstream",
                "_models_prefix": Path("/source_models"),
                "_converted_models": Path(prefix) / 'converted_models',
                "adapter": "classification",
                "use_cached_model": True
            }
            DLSDKLauncher(config, dummy_adapter)

        mock.assert_not_called()
Esempio n. 23
0
    def test_model_converted_with_mo_flags(self, mocker):
        mock = mocker.patch(
            'accuracy_checker.launcher.dlsdk_launcher.convert_model',
            return_value=('converted_model', 'converted_weights'))

        config = {
            'framework': 'dlsdk',
            'caffe_model': '/path/to/source_models/custom_model',
            'caffe_weights': '/path/to/source_models/custom_weights',
            'device': 'cpu',
            'bitstream': Path('custom_bitstream'),
            '_models_prefix': '/path/to/source_models',
            'mo_flags': ['reverse_input_channels'],
            'adapter': 'classification'
        }

        DLSDKLauncher(config, dummy_adapter)

        mock.assert_called_once_with('custom_model',
                                     '/path/to/source_models/custom_model',
                                     '/path/to/source_models/custom_weights',
                                     'caffe', [], None,
                                     ['reverse_input_channels'], None, None)
Esempio n. 24
0
    def test_model_converted_from_tf_with_arg_path_to_custom_tf_config(
            self, mocker):
        config = {
            'framework': 'dlsdk',
            'tf_model': '/path/to/source_models/custom_model',
            'device': 'cpu',
            '_models_prefix': '/path/to',
            'adapter': 'classification',
            'mo_params': {
                'tensorflow_use_custom_operations_config':
                'ssd_v2_support.json'
            },
            '_tf_custom_op_config_dir': 'config/dir'
        }
        mocker.patch('accuracy_checker.launcher.model_conversion.find_mo',
                     return_value=Path('/path/ModelOptimizer'))
        prepare_args_patch = mocker.patch(
            'accuracy_checker.launcher.model_conversion.prepare_args')

        args = {
            'input_model':
            '/path/to/source_models/custom_model',
            'model_name':
            'custom_model',
            'framework':
            'tf',
            'tensorflow_use_custom_operations_config':
            'config/dir/ssd_v2_support.json'
        }

        mocker.patch(
            'accuracy_checker.launcher.model_conversion.exec_mo_binary',
            return_value=subprocess.CompletedProcess(args, returncode=0))
        DLSDKLauncher(config, dummy_adapter)
        prepare_args_patch.assert_called_once_with('/path/ModelOptimizer',
                                                   flag_options=[],
                                                   value_options=args)
    def test_model_converted_from_tf_checkpoint_with_default_path_to_custom_tf_config(self, mocker):
        config = {
            'framework': 'dlsdk',
            'tf_meta': '/path/to/source_models/custom_model',
            'device': 'cpu',
            'adapter': 'classification',
            'mo_params': {'tensorflow_use_custom_operations_config': 'config.json'}
        }
        mocker.patch('accuracy_checker.launcher.model_conversion.find_mo', return_value=self.FAKE_MO_PATH)
        prepare_args_patch = mocker.patch('accuracy_checker.launcher.model_conversion.prepare_args')

        args = {
            'input_meta_graph': '/path/to/source_models/custom_model',
            'model_name': 'custom_model',
            'framework': 'tf',
            'tensorflow_use_custom_operations_config': str(Path('/path/extensions/front/tf/config.json').absolute())
        }

        mocker.patch(
            'accuracy_checker.launcher.model_conversion.exec_mo_binary',
            return_value=subprocess.CompletedProcess(args, returncode=0)
        )
        DLSDKLauncher(config)
        prepare_args_patch.assert_called_once_with(str(self.FAKE_MO_PATH), flag_options=[], value_options=args)