示例#1
0
    def test_does_not_program_bitstream_when_hetero_without_fpga(self, mocker):
        subprocess_mock = mocker.patch('subprocess.run')

        config = {
            'framework': 'dlsdk',
            'weights': 'custom_weights',
            'model': 'custom_model',
            'device': 'hetero:cpu,cpu',
            'bitstream': Path('custom_bitstream'),
            'adapter': 'classification',
            '_aocl': Path('aocl')
        }
        create_launcher(config, model_name='custom')
        subprocess_mock.assert_not_called()
示例#2
0
    def test_does_not_set_dla_aocx_when_hetero_without_fpga(self, mocker):
        mocker.patch('os.environ')

        config = {
            'framework': 'dlsdk',
            'weights': 'custom_weights',
            'model': 'custom_model',
            'device': 'hetero:cpu,cpu',
            'bitstream': 'custom_bitstream',
            'adapter': 'classification',
            '_models_prefix': 'prefix'
        }
        create_launcher(config)

        os.environ.__setitem__.assert_not_called()
    def test_does_not_set_dla_aocx_when_hetero_without_fpga(self, mocker):
        mocker.patch('os.environ')

        config = {
            "framework": "dlsdk",
            "weights": 'custom_weights',
            "model": 'custom_model',
            "device": 'hetero:cpu,cpu',
            "bitstream": "custom_bitstream",
            "adapter": "classification"
        }
        mock_inputs(mocker)
        create_launcher(config)

        os.environ.__setitem__.assert_not_called()
    def test_missed_type_in_dir_adapter_in_create_dlsdk_launcher_raises_config_error_exception(
            self, mocker):
        mock_inference_engine(mocker)
        mock_inputs(mocker)
        launcher_config = {
            'framework': 'dlsdk',
            'model': 'custom',
            'weights': 'custom',
            'adapter': {
                'key': 'val'
            }
        }

        with pytest.raises(ConfigError):
            create_launcher(launcher_config)
    def test_sets_dla_aocx_when_fpga_in_hetero_device(self, mocker):
        mocker.patch('os.environ')

        config = {
            "framework": "dlsdk",
            "weights": 'custom_weights',
            "model": 'custom_model',
            "device": 'hetero:fpga,cpu',
            "bitstream": "custom_bitstream",
            "adapter": 'classification'
        }
        mock_inputs(mocker)
        create_launcher(config, {'label_map': {}})
        os.environ.__setitem__.assert_called_once_with('DLA_AOCX',
                                                       'custom_bitstream')
    def test_dlsdk_launcher_model_no_image_inputs_raise_value_error(
            self, mocker):
        mock_inference_engine(mocker)

        launcher_config = {
            'framework': 'dlsdk',
            'model': 'custom',
            'weights': 'custom',
            'adapter': {
                'key': 'val'
            }
        }

        with pytest.raises(ValueError):
            create_launcher(launcher_config)
    def test_does_not_set_dla_aocx_if_compiler_mode_3_in_env_when_fpga_in_device(self, mocker):
        mocker.patch('os.environ')
        mocker.patch('os.environ.get', return_value='3')

        config = {
            'framework': 'dlsdk',
            'weights': 'custom_weights',
            'model': 'custom_model',
            'device': 'fpga',
            'bitstream': 'custom_bitstream',
            'adapter': 'classification',
        }
        create_launcher(config)

        os.environ.__setitem__.assert_not_called()
示例#8
0
    def test_sets_dla_aocx_when_fpga_in_hetero_device(self, mocker):
        mocker.patch('os.environ')

        config = {
            'framework': 'dlsdk',
            'weights': 'custom_weights',
            'model': 'custom_model',
            'device': 'hetero:fpga,cpu',
            'bitstream': Path('custom_bitstream'),
            'adapter': 'classification',
            '_models_prefix': 'prefix'
        }
        create_launcher(config)
        os.environ.__setitem__.assert_called_once_with('DLA_AOCX',
                                                       'custom_bitstream')
    def test_does_not_program_bitstream_if_compiler_mode_3_in_env_when_fpga_in_device(self, mocker):
        subprocess_mock = mocker.patch('subprocess.run')
        mocker.patch('os.environ.get', return_value='3')

        config = {
            'framework': 'dlsdk',
            'weights': 'custom_weights',
            'model': 'custom_model',
            'device': 'fpga',
            'bitstream': Path('custom_bitstream'),
            'adapter': 'classification',
            '_aocl': Path('aocl')
        }
        create_launcher(config)

        subprocess_mock.assert_not_called()
    def test_does_not_set_dla_aocx_if_compiler_mode_3_in_env_when_fpga_in_device(
            self, mocker):
        mocker.patch('os.environ')
        mocker.patch('os.environ.get', return_value='3')

        config = {
            "framework": "dlsdk",
            "weights": 'custom_weights',
            "model": 'custom_model',
            "device": 'fpga',
            "bitstream": "custom_bitstream",
            "adapter": "classification"
        }
        create_launcher(config)

        os.environ.__setitem__.assert_not_called()
示例#11
0
 def test_missed_framework_in_create_opencv_launcher_raises_config_error_exception(
         self):
     config = {
         # 'framework': 'opencv',
         'model': 'model.ocv',
         'weights': 'weights.ocv',
         'device': 'not_device',
         'backend': 'not_backend',
         'adapter': 'classification',
         'inputs': [{
             'name': 'data',
             'type': 'INPUT'
         }]
     }
     with pytest.raises(KeyError):
         create_launcher(config)
示例#12
0
 def test_missed_device_in_create_gapi_launcher_raises_config_error_exception(
         self):
     config = {
         'framework': 'g-api',
         'model': 'model.xml',
         'weights': 'weights.bin',
         # 'device': 'not_device',
         'adapter': 'classification',
         'inputs': [{
             'name': 'data',
             'type': 'INPUT'
         }],
         'outputs': ['out']
     }
     with pytest.raises(ConfigError):
         create_launcher(config)
 def test_auto_model_search(self, models_dir):
     config = {
         "framework": "onnx_runtime",
         "model": models_dir,
     }
     launcher = create_launcher(config, 'samplenet')
     assert launcher.model == models_dir / "samplenet.onnx"
def get_pdpd_test_model(models_dir):
    config = {
        "framework": "paddle_paddle",
        "model": str(models_dir / "samplenet.pdmodel"),
        'params': str(models_dir / 'samplenet.pdiparams'),
        "adapter": "classification",
    }
    return create_launcher(config)
def get_onnx_test_model(models_dir):
    config = {
        "framework": "onnx_runtime",
        "model": str(models_dir / "samplenet.onnx"),
        "adapter": "classification",
        "device": "cpu",
    }
    return create_launcher(config)
    def test_dlsdk_launcher_model_with_several_image_inputs_raise_value_error(
            self, mocker):
        launcher_config = {
            'framework': 'dlsdk',
            'model': 'custom',
            'weights': 'custom',
            'adapter': {
                'key': 'val'
            }
        }

        with pytest.raises(ValueError):
            mocker.patch(
                'accuracy_checker.launcher.dlsdk_launcher.DLSDKLauncher.inputs',
                new_callable=PropertyMock(return_value={
                    'data1': [3, 227, 227],
                    'data2': [3, 227, 227]
                }))
            create_launcher(launcher_config)
示例#17
0
def get_caffe_test_model(models_dir):
    config = {
        "framework": "caffe",
        "weights": str(models_dir / "SampLeNet.caffemodel"),
        "model": str(models_dir / "SampLeNet.prototxt"),
        "adapter": 'classification',
        "device": "cpu"
    }

    return create_launcher(config)
def get_pth_test_model(models_dir):
    config = {
        "framework": 'pytorch',
        "module": 'samplenet.SampLeNet',
        "checkpoint": models_dir / 'pytorch_model' / 'samplenet.pth',
        'python_path': models_dir / 'pytorch_model',
        "adapter": 'classification',
        "device": 'cpu',
    }

    return create_launcher(config)
 def test_caffe_launcher_model_search(self, models_dir):
     config = {
         "framework": "caffe",
         "weights": models_dir,
         "model": models_dir,
         "adapter": 'classification',
         "device": "cpu"
     }
     caffe_model = create_launcher(config, 'SampleNet')
     assert caffe_model.model == models_dir / 'SampLeNet.prototxt'
     assert caffe_model.weights == models_dir / 'SampLeNet.caffemodel'
def get_dlsdk_test_blob(models_dir, config_update=None):
    config = {
        'framework': 'dlsdk',
        'model': str(models_dir / 'SampLeNet.blob'),
        'device': 'MYRIAD',
        'adapter': 'classification',
    }
    if config_update:
        config.update(config_update)

    return create_launcher(config)
def get_onnx_test_model(model_dir, config_update=None):
    config = {
        'framework': 'dlsdk',
        'model': str(model_dir / 'samplenet.onnx'),
        'device': 'CPU',
        'adapter': 'classification'
    }
    if config_update:
        config.update(config_update)

    return create_launcher(config)
示例#22
0
def get_tf_test_model(models_dir, config_update=None):
    config = {
        "framework": "tf",
        "model": str(models_dir / "samplenet.pb"),
        "adapter": 'classification',
        "device": "cpu"
    }
    if config_update:
        config.update(config_update)

    return create_launcher(config)
def get_onnx_test_model(models_dir, device=None, ep=None):
    config = {
        "framework": "onnx_runtime",
        "model": str(models_dir / "samplenet.onnx"),
        "adapter": "classification",
    }
    if device is not None:
        config['device'] = device
    if ep is not None:
        config['execution_providers'] = ep
    return create_launcher(config)
示例#24
0
def dlsdk_test_model(models_dir):
    config = {
        "framework": "dlsdk",
        "weights": str(models_dir / "SampLeNet.bin"),
        "model": str(models_dir / "SampLeNet.xml"),
        "device": "CPU",
        "adapter": 'classification'
    }

    model = create_launcher(config)
    return model
def get_mx_test_model(models_dir, config_override=None):
    config = {
        "framework": 'mxnet',
        "model": models_dir / 'samplenet-0000.params',
        "adapter": 'classification',
        "device": 'cpu',
        'inputs': [{'name': 'data', 'type': 'INPUT', 'shape': '3,32,32'}]
    }
    if config_override:
        config.update(config_override)

    return create_launcher(config)
def get_dlsdk_test_model(models_dir, config_update=None):
    config = {
        'framework': 'dlsdk',
        'weights': str(models_dir / 'SampLeNet.bin'),
        'model': str(models_dir / 'SampLeNet.xml'),
        'device': 'CPU',
        'adapter': 'classification',
    }
    if config_update:
        config.update(config_update)

    return create_launcher(config)
示例#27
0
def get_opencv_test_onnx_model(models_dir):
    config = {
        "framework": "opencv",
        "model": str(models_dir / "samplenet.onnx"),
        "adapter": "classification",
        "device": "cpu",
        "backend": "ocv",
        "inputs": [{
            "name": "input",
            "type": "INPUT",
            "shape": "(3, 32, 32)"
        }]
    }
    return create_launcher(config)
 def test_program_bitstream_when_fpga_in_hetero_device(self, mocker):
     subprocess_mock = mocker.patch('subprocess.run')
     config = {
         'framework': 'dlsdk',
         'weights': 'custom_weights',
         'model': 'custom_model',
         'device': 'hetero:fpga,cpu',
         'bitstream': Path('custom_bitstream'),
         'adapter': 'classification',
         '_aocl': Path('aocl')
     }
     launcher = create_launcher(config)
     subprocess_mock.assert_called_once_with(['aocl', 'program', 'acl0', 'custom_bitstream'], check=True)
     launcher.release()
示例#29
0
def get_gapi_test_model(models_dir):
    config = {
        "framework": "g-api",
        #"weights": str(models_dir / "SampLeNet.bin"),
        "model": models_dir,
        "adapter": "classification",
        "device": "cpu",
        "inputs": [{
            "name": "data",
            "type": "INPUT",
            "shape": "(3, 32, 32)"
        }],
        'outputs': ['fc3']
    }
    return create_launcher(config)
示例#30
0
def get_opencv_test_caffe_model(models_dir):
    config = {
        "framework": "opencv",
        "weights": str(models_dir / "SampLeNet.caffemodel"),
        "model": str(models_dir / "SampLeNet.prototxt"),
        "adapter": "classification",
        "device": "cpu",
        "backend": "ocv",
        "inputs": [{
            "name": "input",
            "type": "INPUT",
            "shape": "(3, 32, 32)"
        }]
    }
    return create_launcher(config)