def test_find_mo_is_none_when_not_exist():
    mo_hierarchy = ['deployment_tools/model_optimizer/mo.py']

    with mock_filesystem(mo_hierarchy) as prefix:
        path = Path(prefix)

        assert find_mo([(path / 'deployment_tools').as_posix()]) is None
    def test_converted_twice_from_mxnet_if_not_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",
                "mxnet_weights": '/source_models/bar/custom_model.params',
                "device": 'cpu',
                "bitstream": "custom_bitstream",
                "_models_prefix": Path("/source_models"),
                "_converted_models": Path(prefix) / 'converted_models',
                "adapter": "classification",
                "use_cached_model": False
            }
            DLSDKLauncher(config, dummy_adapter)

        mock.assert_called_once_with(
            'custom_model', config['_converted_models'] / 'bar', None,
            PosixPath('/source_models/bar/custom_model.params'), 'mxnet', [],
            None)
    def test_not_converted_twice_and_warn_ignore_mo_params_from_caffe_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",
                "caffe_model": '/source_models/bar/custom_model.prototxt',
                "caffe_weights": '/source_models/bar/custom_model.caffemodel',
                "device": 'cpu',
                "bitstream": "custom_bitstream",
                "_models_prefix": Path("/source_models"),
                "_converted_models": Path(prefix) / 'converted_models',
                "adapter": "classification",
                "use_cached_model": True,
                'mo_params': {
                    'data_type': 'FP16'
                }
            }
            with pytest.warns(UserWarning) as warnings:
                DLSDKLauncher(config, dummy_adapter)
                assert len(warnings) == 1

        mock.assert_not_called()
def test_find_mo_list_not_corrupted():
    mo_hierarchy = ['deployment_tools/model_optimizer/mo.py']

    with mock_filesystem(mo_hierarchy) as prefix:
        search_paths = [prefix]

        find_mo(search_paths)

        assert len(search_paths) == 1
def test_find_mo():
    mo_hierarchy = ['deployment_tools/model_optimizer/mo.py']

    with mock_filesystem(mo_hierarchy) as prefix:
        path = Path(prefix)

        assert find_mo([
            (path / 'deployment_tools' / 'model_optimizer').as_posix()
        ])
    def test_path_is_checked(self):
        with mock_filesystem(['foo/bar']) as prefix:
            prefix_path = Path(prefix)
            file_field = PathField(is_directory=False)
            with pytest.raises(ConfigError):
                file_field.validate(prefix_path / 'foo')
            file_field.validate(prefix_path / 'foo' / 'bar')

            dir_field = PathField(is_directory=True)
            dir_field.validate(prefix_path / 'foo')

            with pytest.raises(ConfigError):
                dir_field.validate(prefix_path / 'foo' / 'bar')
    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()
Example #8
0
def test_find_ir_raises_file_not_found_error_when_ir_not_found():
    with mock_filesystem(['foo/']) as root:
        with pytest.raises(FileNotFoundError):
            find_dlsdk_ir(root, 'model')
Example #9
0
def test_find_ir__in_root():
    with mock_filesystem(['model.xml', 'model.bin']) as root:
        model, weights = find_dlsdk_ir(root, 'model')
        assert model == root / 'model.xml'
        assert weights == root / 'model.bin'
Example #10
0
def test_find_mo_is_none_when_not_exist():
    with mock_filesystem(['deployment_tools/model_optimizer/mo.py']) as prefix:
        assert find_mo([prefix / 'deployment_tools']) is None
Example #11
0
def test_find_mo():
    with mock_filesystem(['deployment_tools/model_optimizer/mo.py']) as prefix:
        assert find_mo([prefix / 'deployment_tools' / 'model_optimizer'])
Example #12
0
def test_mock_file_system():
    with mock_filesystem(['foo/bar', 'foo/baz/']) as prefix:
        assert (prefix / 'foo' / 'bar').is_file()
        assert (prefix / 'foo' / 'baz').is_dir()
 def test_path_not_checked(self):
     with mock_filesystem(['foo/bar']) as prefix:
         prefix_path = Path(prefix)
         file_field = PathField(is_directory=False, check_exists=False)
         file_field.validate(prefix_path / 'foo' / 'bar')
def test_find_ir__not_found():
    with mock_filesystem(['foo/']) as root:
        model, weights = find_dlsdk_ir(root)
        assert model is None
        assert weights is None
def test_find_ir__in_subdir():
    with mock_filesystem(['foo/model.xml', 'foo/model.bin']) as root:
        model, weights = find_dlsdk_ir(root)
        assert model.endswith('.xml')
        assert weights.endswith('.bin')
def test_mock_file_system():
    hierarchy = ['foo/bar', 'foo/baz/']
    with mock_filesystem(hierarchy) as prefix:
        assert (Path(prefix) / 'foo' / 'bar').is_file()
        assert (Path(prefix) / 'foo' / 'baz').is_dir()