Skip to content

Commit dda7a68

Browse files
authored
AC: update test model (openvinotoolkit#873)
1 parent f6287f4 commit dda7a68

File tree

5 files changed

+118
-3
lines changed

5 files changed

+118
-3
lines changed

tools/accuracy_checker/accuracy_checker/launcher/dlsdk_launcher_readme.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ For enabling OpenVINO™ launcher you need to add `framework: dlsdk` in launcher
66
Heterogeneous plugin as `HETERO:target_device,fallback_device` and Multi device plugin as `MULTI:target_device1,target_device2`.
77
If you have several MYRIAD devices in your machine, you are able to provide specific device id in such way: `MYRIAD.<DEVICE_ID>` (e.g. `MYRIAD.1.2-ma2480`)
88
It is possible to specify one or more devices via `-td, --target devices` command line argument. Target device will be selected from command line (in case when several devices provided, evaluations will be run one by one with all specified devices).
9-
* `model` - path to xml file with Caffe model for your topology.
10-
* `weights` - path to bin file with weights for your topology.
9+
* `model` - path to xml file with model for your topology or compiled executable network.
10+
* `weights` - path to bin file with weights for your topology (Optional, the argument can be omitted if bin file stored in the same directory with model xml or if you use compiled blob).
11+
12+
**Note:**
13+
You can generate executable blob using [compile_tool](http://docs.openvinotoolkit.org/latest/_inference_engine_tools_compile_tool_README.html).
14+
Before evaluation executable blob, please make sure that selected device support it.
15+
1116

1217
launcher may optionally provide model parameters in source framework format which will be converted to Inference Engine IR using Model Optimizer.
1318
If you want to use Model Optimizer for model conversion, please view [Model Optimizer Developer Guide](https://software.intel.com/en-us/articles/OpenVINO-ModelOptimizer).
Binary file not shown.

tools/accuracy_checker/sample/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,10 @@ Used options: `-c` path to evaluation config, `-m` directory where models are st
3838
If everything worked correctly, you should be able to get `75.02%` accuracy.
3939

4040
Now try edit config, to run SampLeNet on other device or framework (e.g. Caffe, MXNet or OpenCV), or go directly to your topology!
41+
42+
43+
### Additional useful resources
44+
45+
* [config](opencv_sample_config.yml) for running SampleNet via [OpenCV launcher](../accuracy_checker/launcher/opencv_launcher_readme.md)
46+
* [config](sample_blob_config.yml) for running SampleNet using compiled executable network blob.
47+
**Note: Not all OpenVINO plugins support compiled network blob execution**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
models:
2+
- name: SampLeNet_example
3+
4+
# list of launchers for your topology.
5+
launchers:
6+
# launcher framework (e.g. caffe, dlsdk)
7+
- framework: dlsdk
8+
# device for infer (e.g. for dlsdk cpu, gpu, hetero:cpu,gpu ...)
9+
# Note: not all devices support blob execution, it is the reason why for sample we will use myriad.
10+
device: MYRIAD
11+
# exported executable network blob
12+
# you can export executable network blob from OpenVINO IR using compile_tool, see http://docs.openvinotoolkit.org/latest/_inference_engine_tools_compile_tool_README.html
13+
# path to model is prefixed with directory, specified in "-m/--models" option
14+
model: SampleNet.blob
15+
# launcher returns raw result, so it should be converted
16+
# to an appropriate representation with adapter
17+
adapter: classification
18+
19+
# metrics, preprocessing and postprocessing are typically dataset specific, so dataset field
20+
# specifies data and all other steps required to validate topology
21+
# there is typically definitions file, which contains options for common datasets and which is merged
22+
# during evaluation, but since "sample_dataset" is not used anywhere else, this config contains full definition
23+
datasets:
24+
# uniquely distinguishable name for dataset
25+
# note that all other steps are specific for this dataset only
26+
# if you need to test topology on multiple datasets, you need to specify
27+
# every step explicitly for each dataset
28+
- name: sample_dataset
29+
# directory where input images are searched.
30+
# prefixed with directory specified in "-s/--source" option
31+
data_source: sample_dataset/test
32+
# parameters for annotation conversion to a common annotation representation format.
33+
annotation_conversion:
34+
# specified which annotation converter will be used
35+
# In order to do this you need to provide your own annotation converter,
36+
# i.e. implement BaseFormatConverter interface.
37+
# All annotation converters are stored in accuracy_checker/annotation_converters directory.
38+
converter: cifar
39+
# converter specific parameters.
40+
# Full range available options you can find in accuracy_checker/annotation_converters/README.md
41+
# relative paths will be merged with "-s/--source" option
42+
data_batch_file: cifar-10-batches-py/test_batch
43+
# cifar stores images as binary file, we should convert them to png in first evaluation.
44+
# Yo do not need to use these options if you have already converted dataset images.
45+
convert_images: True
46+
# path to save converted images.
47+
converted_images_dir: sample_dataset/test
48+
# number of classes in the dataset, used for label_map generation
49+
num_classes: 10
50+
51+
# list of preprocessing, applied to each image during validation
52+
# order of entries matters
53+
preprocessing:
54+
# resize input image to topology input size
55+
# you may specify size to which image should be resized
56+
# via dst_width, dst_height fields
57+
- type: resize
58+
size: 32
59+
# topology is trained on RGB images, but OpenCV reads in BGR
60+
# thence it must be converted to RGB
61+
- type: bgr_to_rgb
62+
# dataset mean and standard deviation
63+
- type: normalization
64+
# you may specify precomputed statistics manually or use precomputed values, such as ImageNet as well
65+
mean: (125.307, 122.961, 113.8575)
66+
std: (51.5865, 50.847, 51.255)
67+
68+
# list of metrics, calculated on dataset
69+
metrics:
70+
- type: accuracy
71+
top_k: 1

tools/accuracy_checker/tests/test_dlsdk_launcher.py

+33-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@
3434
from accuracy_checker.data_readers import DataRepresentation
3535
from accuracy_checker.utils import contains_all
3636

37+
def no_available_myriad():
38+
try:
39+
from openvino.inference_engine import IECore
40+
return 'MYRIAD' not in IECore().availabe_devices
41+
except:
42+
return True
43+
3744

3845
@pytest.fixture()
3946
def mock_inference_engine(mocker):
@@ -63,6 +70,20 @@ def get_dlsdk_test_model(models_dir, config_update=None):
6370
return create_launcher(config)
6471

6572

73+
def get_dlsdk_test_blob(models_dir, config_update=None):
74+
config = {
75+
'framework': 'dlsdk',
76+
'model': str(models_dir / 'SampLeNet.blob'),
77+
'device': 'MYRIAD',
78+
'adapter': 'classification',
79+
'_models_prefix': str(models_dir)
80+
}
81+
if config_update:
82+
config.update(config_update)
83+
84+
return create_launcher(config)
85+
86+
6687
def get_image(image_path, input_shape):
6788
_, _, h, w = input_shape
6889
img_raw = cv2.imread(str(image_path))
@@ -91,10 +112,21 @@ def test_infer_with_additional_outputs(self, models_dir):
91112
assert contains_all(outputs, ['fc1', 'fc2', 'fc3'])
92113
assert dlsdk_test_model.output_blob == 'fc3'
93114

94-
def test_dlsd_launcher_set_batch_size(self, models_dir):
115+
def test_dlsdk_launcher_set_batch_size(self, models_dir):
95116
dlsdk_test_model = get_dlsdk_test_model(models_dir, {'batch': 2})
96117
assert dlsdk_test_model.batch == 2
97118

119+
@pytest.mark.skipif(no_available_myriad(), reason='no myriad device in the system')
120+
def test_dlsdk_launcher_import_network(self, data_dir, models_dir):
121+
dlsdk_test_model = get_dlsdk_test_blob(models_dir)
122+
image = get_image(data_dir / '1.jpg', dlsdk_test_model.inputs['data'].shape)
123+
input_blob = np.transpose([image.data], (0, 3, 1, 2))
124+
result = dlsdk_test_model.predict([{'data': input_blob.astype(np.float32)}], [image.metadata])
125+
assert dlsdk_test_model.output_blob == 'fc3'
126+
127+
assert np.argmax(result[0][dlsdk_test_model.output_blob]) == 7
128+
assert image.metadata['input_shape'] == {'data': [1, 3, 32, 32]}
129+
98130

99131
@pytest.mark.usefixtures('mock_path_exists')
100132
class TestDLSDKLauncherAffinity:

0 commit comments

Comments
 (0)