Skip to content

Commit c889f78

Browse files
author
akorobeinikov
committed
change delimeter for layouts
1 parent 2688a81 commit c889f78

File tree

12 files changed

+18
-22
lines changed

12 files changed

+18
-22
lines changed

demos/bert_named_entity_recognition_demo/python/bert_named_entity_recognition_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def build_argparser():
5858
required=False, type=str, default="input_ids,attention_mask,token_type_ids")
5959
args.add_argument('--layout',
6060
help='Optional. Model inputs layouts. '
61-
'Format "NCHW" or "<input1>:<layout1>,<input2>:<layout2>" in case of more than one input.'
61+
'Format "[<layout>]" or "<input1>[<layout1>],<input2>[<layout2>]" in case of more than one input.'
6262
'To define layout you should use only capital letters',
6363
type=str, default=None)
6464
args.add_argument("-d", "--device",

demos/bert_question_answering_demo/python/bert_question_answering_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def build_argparser():
5757
required=False, type=str, default="input_ids,attention_mask,token_type_ids")
5858
args.add_argument('--layout', type=str, default=None,
5959
help='Optional. Model inputs layouts. '
60-
'Format "NCHW" or "<input1>:<layout1>,<input2>:<layout2>" in case of more than one input.'
60+
'Format "[<layout>]" or "<input1>[<layout1>],<input2>[<layout2>]" in case of more than one input.'
6161
'To define layout you should use only capital letters')
6262
args.add_argument("--output_names",
6363
help="Optional. Outputs names for the network. "

demos/bert_question_answering_embedding_demo/python/bert_question_answering_embedding_demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def build_argparser():
6262
required=False, type=str)
6363
args.add_argument('--layout_emb', type=str, default=None,
6464
help='Optional. MODEL_EMB inputs layouts. '
65-
'Format "NCHW" or "<input1>:<layout1>,<input2>:<layout2>" in case of more than one input.'
65+
'Format "[<layout>]" or "<input1>[<layout1>],<input2>[<layout2>]" in case of more than one input.'
6666
'To define layout you should use only capital letters')
6767
args.add_argument("-m_qa", "--model_qa",
6868
help="Optional. Path to an .xml file with a trained model to give exact answer",
@@ -81,7 +81,7 @@ def build_argparser():
8181
default="1.2", required=False, type=str)
8282
args.add_argument('--layout_qa', type=str, default=None,
8383
help='Optional. MODEL_QA inputs layouts. '
84-
'Format "NCHW" or "<input1>:<layout1>,<input2>:<layout2>" in case of more than one input.'
84+
'Format "[<layout>]" or "<input1>[<layout1>],<input2>[<layout2>]" in case of more than one input.'
8585
'To define layout you should use only capital letters')
8686
args.add_argument("-a", "--max_answer_token_num",
8787
help="Optional. Maximum number of tokens in exact answer",

demos/classification_demo/python/classification_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def build_argparser():
6060
type=int, choices=range(1, 11))
6161
common_model_args.add_argument('--layout', type=str, default=None,
6262
help='Optional. Model inputs layouts. '
63-
'Format "NCHW" or "<input1>:<layout1>,<input2>:<layout2>" in case of more than one input.'
63+
'Format "[<layout>]" or "<input1>[<layout1>],<input2>[<layout2>]" in case of more than one input.'
6464
'To define layout you should use only capital letters')
6565

6666
infer_args = parser.add_argument_group('Inference options')

demos/common/python/openvino/model_zoo/model_api/adapters/openvino_adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def __init__(self, core, model_path, weights_path=None, model_parameters = {}, d
4949
self.plugin_config = plugin_config
5050
self.max_num_requests = max_num_requests
5151
self.model_parameters = model_parameters
52+
self.model_parameters['input_layouts'] = Layout.parse_layouts(self.model_parameters.get('input_layouts', None))
5253

5354
if isinstance(model_path, (str, Path)):
5455
if Path(model_path).suffix == ".onnx" and weights_path:
@@ -87,7 +88,6 @@ def log_runtime_settings(self):
8788

8889
def get_input_layers(self):
8990
inputs = {}
90-
self.model_parameters['input_layouts'] = Layout.parse_layouts(self.model_parameters.get('input_layouts', None))
9191
for input in self.model.inputs:
9292
input_layout = self.get_layout_for_input(input)
9393
inputs[input.get_any_name()] = Metadata(input.get_names(), list(input.shape), input_layout, input.get_element_type().get_type_name())

demos/common/python/openvino/model_zoo/model_api/adapters/utils.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,17 @@ def from_user_layouts(input_names: set, user_layouts: dict):
5555
@staticmethod
5656
def parse_layouts(layout_regex: str) -> Optional[dict]:
5757
'''
58-
Parse layout parameter in format "input0:NCHW,input1:NC" or "NCHW" (applied to all inputs)
58+
Parse layout parameter in format "input0[NCHW],input1[NC]" or "[NCHW]" (applied to all inputs)
5959
'''
6060
if not layout_regex:
6161
return None
6262
inputs_layouts = layout_regex.split(',')
6363
user_layouts = {}
6464
for layout in inputs_layouts:
65-
layout_list = layout.split(':')
66-
if len(layout_list) == 2:
67-
input_name, input_layout = layout_list
68-
else:
69-
input_name = ''
70-
input_layout = layout_list[0]
71-
if re.fullmatch(r"[A-Z]+", input_layout):
72-
user_layouts[input_name] = input_layout
73-
else:
65+
if not re.fullmatch(r"[^\[\]]*\[[A-Z]+\]", layout):
7466
raise ValueError("invalid --layout option format")
67+
layout_list = layout.split('[')
68+
input_name = layout_list[0]
69+
input_layout = layout_list[1].strip('[]')
70+
user_layouts[input_name] = input_layout
7571
return user_layouts

demos/common/python/openvino/model_zoo/model_api/models/deblurring.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2021 Intel Corporation
2+
Copyright (c) 2021-2022 Intel Corporation
33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.
55
You may obtain a copy of the License at

demos/deblurring_demo/python/deblurring_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def build_argparser():
5454
'Default value is CPU.')
5555
args.add_argument('--layout', type=str, default=None,
5656
help='Optional. Model inputs layouts. '
57-
'Format "NCHW" or "<input1>:<layout1>,<input2>:<layout2>" in case of more than one input.'
57+
'Format "[<layout>]" or "<input1>[<layout1>],<input2>[<layout2>]" in case of more than one input.'
5858
'To define layout you should use only capital letters')
5959

6060
infer_args = parser.add_argument_group('Inference options')

demos/human_pose_estimation_demo/python/human_pose_estimation_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def build_argparser():
8080
'is the length of a short first image side.')
8181
common_model_args.add_argument('--layout', type=str, default=None,
8282
help='Optional. Model inputs layouts. '
83-
'Format "NCHW" or "<input1>:<layout1>,<input2>:<layout2>" in case of more than one input.'
83+
'Format "[<layout>]" or "<input1>[<layout1>],<input2>[<layout2>]" in case of more than one input.'
8484
'To define layout you should use only capital letters')
8585

8686
infer_args = parser.add_argument_group('Inference options')

demos/monodepth_demo/python/monodepth_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def build_argparser():
6060
'Default value is CPU.')
6161
args.add_argument('--layout', type=str, default=None,
6262
help='Optional. Model inputs layouts. '
63-
'Format "NCHW" or "<input1>:<layout1>,<input2>:<layout2>" in case of more than one input.'
63+
'Format "[<layout>]" or "<input1>[<layout1>],<input2>[<layout2>]" in case of more than one input.'
6464
'To define layout you should use only capital letters')
6565

6666
infer_args = parser.add_argument_group('Inference options')

0 commit comments

Comments
 (0)