Publishing 2019 R1 content
[platform/upstream/dldt.git] / tools / calibration / command_line_reader.py
1 """
2 Copyright (C) 2018-2019 Intel Corporation
3
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
7
8       http://www.apache.org/licenses/LICENSE-2.0
9
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.
15 """
16
17 import pathlib
18 from functools import partial
19 from argparse import ArgumentParser
20
21 from ..accuracy_checker.accuracy_checker.utils import get_path
22
23
24 class CommandLineReader:
25     @staticmethod
26     def parser():
27         parser = ArgumentParser(description='openvino.tools.calibration')
28
29         parser.add_argument(
30             '-d', '--definitions',
31             help='Optional. Path to the YML file with definitions',
32             type=str,
33             required=False)
34
35         parser.add_argument(
36             '-c', '--config',
37             help='Required. Path to the YML file with local configuration',
38             type=get_path,
39             required=True)
40
41         parser.add_argument(
42             '-m', '--models',
43             help='Optional. Prefix path to the models and weights',
44             type=partial(get_path, is_directory=True),
45             default=pathlib.Path.cwd(),
46             required=False)
47
48         parser.add_argument(
49             '-s', '--source',
50             help='Optional. Prefix path to the data source',
51             type=partial(get_path, is_directory=True),
52             default=pathlib.Path.cwd(),
53             required=False)
54
55         parser.add_argument(
56             '-a', '--annotations',
57             help='Optional. Prefix path to the converted annotations and datasets meta data',
58             type=partial(get_path, is_directory=True),
59             default=pathlib.Path.cwd(),
60             required=False)
61
62         parser.add_argument(
63             '-e', '--extensions',
64             help='Optional. Prefix path to extensions folder',
65             type=partial(get_path, is_directory=True),
66             default=pathlib.Path.cwd(),
67             required=False)
68
69         parser.add_argument(
70             '--cpu_extensions_mode', '--cpu-extensions-mode',
71             help='Optional. specified preferable set of processor instruction for automatic searching cpu extension lib',
72             required=False,
73             choices=['avx2', 'sse4'])
74
75         parser.add_argument(
76             '-C', '--converted_models', '--converted-models',
77             help='Optional. Directory to store Model Optimizer converted models. Used for DLSDK launcher only',
78             type=partial(get_path, is_directory=True),
79             required=False
80         )
81
82         parser.add_argument(
83             '-M', '--model_optimizer', '--model-optimizer',
84             help='Optional. Path to model optimizer caffe directory',
85             type=partial(get_path, is_directory=True),
86             # there is no default value because if user did not specify it we use specific locations
87             # defined in model_conversion.py
88             required=False
89         )
90
91         parser.add_argument(
92             '--tf_custom_op_config_dir', '--tf-custom-op-config-dir',
93             help='Optional. Path to directory with tensorflow custom operation configuration files for model optimizer',
94             type=partial(get_path, is_directory=True),
95             # there is no default value because if user did not specify it we use specific location
96             # defined in model_conversion.py
97             required=False
98         )
99
100         parser.add_argument(
101             '--tf_obj_detection_api_pipeline_config_path', '--tf-obj-detection-api-pipeline-config-path',
102             help='Optional. Path to directory with tensorflow object detection api pipeline configuration files for model optimizer',
103             type=partial(get_path, is_directory=True),
104             # there is no default value because if user did not specify it we use specific location
105             # defined in model_conversion.py
106             required=False
107         )
108
109         parser.add_argument(
110             '--progress',
111             help='Optional. Progress reporter',
112             required=False,
113             default='bar')
114
115         parser.add_argument(
116             '-td', '--target_devices', '--target-devices',
117             help='Optional. Space-separated list of devices for infer',
118             required=False,
119             nargs='+',
120             default=["CPU"]
121         )
122
123         parser.add_argument(
124             '-tt', '--target_tags', '--target-tags',
125             help='Optional. Space-separated list of launcher tags for infer',
126             required=False,
127             nargs='+')
128
129         parser.add_argument(
130             '-p',
131             '--precision',
132             help='Optional. Precision to calibrate. Default value is INT8',
133             type=str,
134             required=False,
135             default='INT8')
136
137         parser.add_argument(
138             '--ignore_layer_types', '--ignore-layer-types',
139             help='Optional. Layer types list which will be skipped during quantization',
140             type=str,
141             required=False,
142             nargs='+')
143
144         parser.add_argument(
145             '--ignore_layer_types_path', '--ignore-layer-types-path',
146             help='Optional. Ignore layer types file path',
147             type=str,
148             required=False,
149             nargs='+')
150
151         parser.add_argument(
152             '--ignore_layer_names', '--ignore-layer-names',
153             help='Optional. Layer names list which will be skipped during quantization',
154             type=str,
155             required=False,
156             nargs='+')
157
158         parser.add_argument(
159             '--ignore_layer_names_path', '--ignore-layer-names-path',
160             help='Optional. Ignore layer names file path',
161             type=str,
162             required=False)
163
164         parser.add_argument(
165             '--batch_size', '--batch-size',
166             help='Optional. Batch size value. If not specified, the batch size value is determined from IR',
167             type=int,
168             required=False)
169
170         parser.add_argument(
171             '-th', '--threshold',
172             help='Optional. Accuracy drop of quantized model should not exceed this threshold. '
173                  'Should be pointer in percents without percent sign. (1%% is default)',
174             type=float,
175             required=False,
176             default=1.0)
177
178         parser.add_argument(
179             '-ic', '--benchmark_iterations_count', '--benchmark-iterations-count',
180             help='Optional. Benchmark itertations count. (1000 is default)',
181             type=int,
182             required=False,
183             default=1000)
184
185         parser.add_argument(
186             '-mn', '--metric_name', '--metric-name',
187             help='Optional. Metric name used during calibration',
188             type=str,
189             required=False)
190
191         parser.add_argument(
192             '-mt', '--metric_type', '--metric-type',
193             help='Optional. Metric type used during calibration',
194             type=str,
195             required=False)
196
197         parser.add_argument(
198             '-o', '--output_dir', '--output-dir',
199             help='Optional. Directory to store converted models. Original model directory is used if not defined',
200             type=partial(get_path, is_directory=True),
201             required=False)
202
203         parser.add_argument(
204             '-cfc', '--calibrate_fully_connected', '--calibrate-fully-connected',
205             help='Optional. FullyConnected INT8 convertion support (False is default)',
206             action="store_true",
207             required=False)
208
209         return parser