Skip to content

Commit a3879ab

Browse files
author
akorobeinikov
committed
align with c++
1 parent f324811 commit a3879ab

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

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
@@ -101,7 +101,7 @@ def get_layout_for_input(self, input) -> str:
101101
if not input_layout:
102102
if not layout_helpers.get_layout(input).empty:
103103
input_layout = Layout.from_openvino(input)
104-
elif len(input.shape) == 4:
104+
else:
105105
input_layout = Layout.from_shape(input.shape)
106106
return input_layout
107107

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,15 @@ def from_shape(shape):
2828
'''
2929
Create Layout from given shape
3030
'''
31-
if len(shape) != 4:
32-
raise RuntimeError('Get layout from shape method supports only 4D input shape')
31+
if len(shape) == 2:
32+
return 'NC'
33+
if len(shape) == 3:
34+
return 'CHW' if shape[0] in range(1, 5) else 'HWC'
35+
if len(shape) == 4:
36+
return 'NCHW' if shape[1] in range(1, 5) else 'NHWC'
37+
38+
raise RuntimeError("Get layout from shape method doesn't support {}D shape".format(len(shape)))
3339

34-
layout = 'NCHW' if shape[1] in range(1, 4) else 'NHWC'
35-
return layout
3640

3741
@staticmethod
3842
def from_openvino(input):

0 commit comments

Comments
 (0)