[MO] cli_parser.py fix to accept scalar value for freezing (#9395)

* cli_parser.py fix to accept scalar value for freezing

* update cli help

* fixed unit-tests, clarified help for specifying data type

* typos correction
This commit is contained in:
Pavel Esir 2021-12-29 01:33:49 +03:00 committed by GitHub
parent 3e6951c1da
commit a51a735d9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 167 additions and 116 deletions

View File

@ -101,18 +101,24 @@ Framework-agnostic parameters:
Parameter -> ReverseInputChannels -> Mean/Scale apply -> the original body of the model.
--log_level {CRITICAL,ERROR,WARN,WARNING,INFO,DEBUG,NOTSET}
Logger level
--input INPUT Quoted list of comma-separated input nodes names with
shapes, data types, and values for freezing. The shape
and value are specified as space-separated lists. The
data type of input node is specified in braces and can
have one of the values: f64 (float64), f32 (float32),
f16 (float16), i64 (int64), i32 (int32), u8 (uint8),
boolean. For example, use the following format to set
input port 0 of the node `node_name1` with the shape
[3 4] as an input node and freeze output port 1 of the
node `node_name2` with the value [20 15] of the int32
type and shape [2]: "0:node_name1[3
4],node_name2:1[2]{i32}->[20 15]".
--input INPUT Quoted list of comma-separated input nodes names with shapes,
data types, and values for freezing. The shape and value are
specified as space-separated lists. The data type of input
node is specified in braces and can have one of the values:
f64 (float64), f32 (float32), f16 (float16), i64 (int64),
i32 (int32), u8 (uint8), boolean (bool). Data type is optional.
If it's not specified explicitly then there are two options:
if input node is a parameter, data type is taken from the
original node dtype, if input node is not a parameter, data type
is set to f32. Example, to set `input_1` with shape [1 100],
and Parameter node `sequence_len` with scalar input with value `150`,
and boolean input `is_training` with `False` value use the
following format: "input_1[1 10],sequence_len->150,is_training->False".
Another example, use the following format to set input port 0
of the node `node_name1` with the shape [3 4] as an input node
and freeze output port 1 of the node `node_name2` with the
value [20 15] of the int32 type and shape [2]:
"0:node_name1[3 4],node_name2:1[2]{i32}->[20 15]".
--output OUTPUT The name of the output operation of the model. For
TensorFlow*, do not add :0 to this name.
--mean_values MEAN_VALUES, -ms MEAN_VALUES

View File

@ -48,6 +48,7 @@ class FreezePlaceholderValue(FrontReplacementSubgraph):
try:
if data_type != np.bool:
value = mo_array(string_value, dtype=data_type)
# TODO: investigate why boolean type is allowed only for TensorFlow
elif data_type == np.bool and graph.graph['fw'] == 'tf':
from openvino.tools.mo.front.tf.common import tf_data_type_cast
if isinstance(string_value, list):
@ -58,9 +59,9 @@ class FreezePlaceholderValue(FrontReplacementSubgraph):
else:
value = tf_data_type_cast[ph.data_type](string_value)
else:
raise Error("Can not cast value {} to {} data_type".format(string_value, data_type))
raise Error("Cannot cast value {} to {} data_type".format(string_value, data_type))
except:
raise Error("Can not cast value {} to {} data_type".format(string_value, data_type))
raise Error("Cannot cast value {} to {} data_type".format(string_value, data_type))
try:
value = np.reshape(a=value, newshape=ph.shape)
except:

View File

@ -289,10 +289,18 @@ def get_common_cli_parser(parser: argparse.ArgumentParser = None):
common_group.add_argument('--input',
help='Quoted list of comma-separated input nodes names with shapes, data types, '
'and values for freezing. The shape and value are specified as space-separated '
'lists. The data type of input node is specified in braces and can have one of the '
'values: f64 (float64), f32 (float32), f16 (float16), i64 (int64), i32 (int32), u8 '
'(uint8), boolean. For example, use the following format to set input port 0 of the '
'node `node_name1` with the shape [3 4] as an input node and freeze output port 1 '
'lists. The data type of input node is specified in braces and '
'can have one of the values: f64 (float64), f32 (float32), f16 (float16), '
'i64 (int64), i32 (int32), u8 (uint8), boolean (bool). Data type is optional. '
'If it\'s not specified explicitly then there are two options: '
'if input node is a parameter, data type is taken from the original node dtype, '
'if input node is not a parameter, data type is set to f32. '
'Example, to set `input_1` with shape [1 100], and Parameter node `sequence_len` '
'with scalar input with value `150`, and boolean input `is_training` with '
'`False` value use the following format: '
'"input_1[1 10],sequence_len->150,is_training->False". '
'Another example, use the following format to set input port 0 of the node '
'`node_name1` with the shape [3 4] as an input node and freeze output port 1 '
'of the node `node_name2` with the value [20 15] of the int32 type and shape [2]: '
'"0:node_name1[3 4],node_name2:1[2]{i32}->[20 15]".')
common_group.add_argument('--output',
@ -796,9 +804,11 @@ def get_shape_from_input_value(input_value: str):
input_value = input_value.split('->')[0]
# parse shape
shape = re.findall(r'[(\[]([0-9\.\? -]+)[)\]]', input_value)
shape = re.findall(r'[(\[]([0-9\.\? -]*)[)\]]', input_value)
if len(shape) == 0:
shape = None
elif len(shape) == 1 and shape[0] in ['', ' ']:
shape = ()
elif len(shape) == 1:
shape = tuple(map(parse_dimension, shape[0].split(' ')))
else:
@ -856,7 +866,7 @@ def parse_input_value(input_value: str):
data_type = get_data_type_from_input_value(input_value)
node_name = get_node_name_with_port_from_input_value(input_value)
value = get_value_from_input_value(input_value)
shape = get_shape_from_input_value(input_value.split('->')[0])
shape = get_shape_from_input_value(input_value)
value_size = np.prod(len(value)) if isinstance(value, list) else 1
if value is not None and shape is not None:
@ -1170,6 +1180,9 @@ def get_placeholder_shapes(argv_input: str, argv_input_shape: str, argv_batch=No
if '->' not in inp:
continue
shape = placeholder_shapes[inp.split('->')[0]]
if shape is None:
continue
for dim in shape:
if isinstance(dim, tuple) or dim == -1:
raise Error("Cannot freeze input with dynamic shape: {}".format(shape))

View File

@ -10,12 +10,11 @@ import unittest
from unittest.mock import patch
import numpy as np
import numpy.testing as npt
from openvino.tools.mo.utils.cli_parser import get_placeholder_shapes, get_tuple_values, get_mean_scale_dictionary, \
get_model_name, \
parse_tuple_pairs, check_positive, writable_dir, readable_dirs, \
readable_file, get_freeze_placeholder_values, parse_transform, check_available_transforms, get_layout_values
readable_file, get_freeze_placeholder_values, parse_transform, check_available_transforms, get_layout_values, get_data_type_from_input_value
from openvino.tools.mo.utils.error import Error
@ -28,7 +27,7 @@ class TestingMeanScaleGetter(unittest.TestCase):
'info': np.array([2.2, 33.33, 444.444])
}
for el in exp_res.keys():
npt.assert_array_equal(result[el], exp_res[el])
assert np.array_equal(result[el], exp_res[el])
def test_tuple_parser_name_digits_only(self):
tuple_values = "0448(1.1,22.22,333.333),0449[2.2,33.33,444.444]"
@ -38,7 +37,7 @@ class TestingMeanScaleGetter(unittest.TestCase):
'0449': np.array([2.2, 33.33, 444.444])
}
for el in exp_res.keys():
npt.assert_array_equal(result[el], exp_res[el])
assert np.array_equal(result[el], exp_res[el])
def test_tuple_parser_same_values(self):
tuple_values = "data(1.1,22.22,333.333),info[1.1,22.22,333.333]"
@ -48,7 +47,7 @@ class TestingMeanScaleGetter(unittest.TestCase):
'info': np.array([1.1, 22.22, 333.333])
}
for el in exp_res.keys():
npt.assert_array_equal(result[el], exp_res[el])
assert np.array_equal(result[el], exp_res[el])
def test_tuple_parser_no_inputs(self):
tuple_values = "(1.1,22.22,333.333),[2.2,33.33,444.444]"
@ -56,7 +55,7 @@ class TestingMeanScaleGetter(unittest.TestCase):
exp_res = [np.array([1.1, 22.22, 333.333]),
np.array([2.2, 33.33, 444.444])]
for i in range(0, len(exp_res)):
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_tuple_parser_error_mixed_with_and_without_name(self):
tuple_values = "(1.1,22.22,333.333),data[2.2,33.33,444.444]"
@ -91,7 +90,7 @@ class TestingMeanScaleGetter(unittest.TestCase):
for input in exp_res.keys():
for key in exp_res[input].keys():
if type(exp_res[input][key]) is np.ndarray:
npt.assert_array_equal(exp_res[input][key], result[input][key])
assert np.array_equal(exp_res[input][key], result[input][key])
else:
self.assertEqual(exp_res[input][key], result[input][key])
@ -112,7 +111,7 @@ class TestingMeanScaleGetter(unittest.TestCase):
for input in exp_res.keys():
for key in exp_res[input].keys():
if type(exp_res[input][key]) is np.ndarray:
npt.assert_array_equal(exp_res[input][key], result[input][key])
assert np.array_equal(exp_res[input][key], result[input][key])
else:
self.assertEqual(exp_res[input][key], result[input][key])
@ -128,7 +127,7 @@ class TestingMeanScaleGetter(unittest.TestCase):
for input in exp_res.keys():
for key in exp_res[input].keys():
if type(exp_res[input][key]) is np.ndarray:
npt.assert_array_equal(exp_res[input][key], result[input][key])
assert np.array_equal(exp_res[input][key], result[input][key])
else:
self.assertEqual(exp_res[input][key], result[input][key])
@ -144,7 +143,7 @@ class TestingMeanScaleGetter(unittest.TestCase):
for input in exp_res.keys():
for key in exp_res[input].keys():
if type(exp_res[input][key]) is np.ndarray:
npt.assert_array_equal(exp_res[input][key], result[input][key])
assert np.array_equal(exp_res[input][key], result[input][key])
else:
self.assertEqual(exp_res[input][key], result[input][key])
@ -163,7 +162,7 @@ class TestingMeanScaleGetter(unittest.TestCase):
for i in range(len(exp_res)):
for j in range(len(exp_res[i])):
if type(exp_res[i][j]) is np.ndarray:
npt.assert_array_equal(exp_res[i][j], result[i][j])
assert np.array_equal(exp_res[i][j], result[i][j])
else:
self.assertEqual(exp_res[i][j], result[i][j])
@ -182,7 +181,7 @@ class TestingMeanScaleGetter(unittest.TestCase):
for input in exp_res.keys():
for key in exp_res[input].keys():
if type(exp_res[input][key]) is np.ndarray:
npt.assert_array_equal(exp_res[input][key], result[input][key])
assert np.array_equal(exp_res[input][key], result[input][key])
else:
self.assertEqual(exp_res[input][key], result[input][key])
@ -205,7 +204,7 @@ class TestingMeanScaleGetter(unittest.TestCase):
for input in exp_res.keys():
for key in exp_res[input].keys():
if type(exp_res[input][key]) is np.ndarray:
npt.assert_array_equal(exp_res[input][key], result[input][key])
assert np.array_equal(exp_res[input][key], result[input][key])
else:
self.assertEqual(exp_res[input][key], result[input][key])
@ -228,7 +227,7 @@ class TestingMeanScaleGetter(unittest.TestCase):
for input in exp_res.keys():
for key in exp_res[input].keys():
if type(exp_res[input][key]) is np.ndarray:
npt.assert_array_equal(exp_res[input][key], result[input][key])
assert np.array_equal(exp_res[input][key], result[input][key])
else:
self.assertEqual(exp_res[input][key], result[input][key])
@ -247,7 +246,7 @@ class TestingMeanScaleGetter(unittest.TestCase):
for input in exp_res.keys():
for key in exp_res[input].keys():
if type(exp_res[input][key]) is np.ndarray:
npt.assert_array_equal(exp_res[input][key], result[input][key])
assert np.array_equal(exp_res[input][key], result[input][key])
else:
self.assertEqual(exp_res[input][key], result[input][key])
@ -270,7 +269,7 @@ class TestingMeanScaleGetter(unittest.TestCase):
for i in range(len(exp_res)):
for j in range(len(exp_res[i])):
if type(exp_res[i][j]) is np.ndarray:
npt.assert_array_equal(exp_res[i][j], result[i][j])
assert np.array_equal(exp_res[i][j], result[i][j])
else:
self.assertEqual(exp_res[i][j], result[i][j])
@ -291,7 +290,7 @@ class TestingMeanScaleGetter(unittest.TestCase):
for input in exp_res.keys():
for key in exp_res[input].keys():
if type(exp_res[input][key]) is np.ndarray:
npt.assert_array_equal(exp_res[input][key], result[input][key])
assert np.array_equal(exp_res[input][key], result[input][key])
else:
self.assertEqual(exp_res[input][key], result[input][key])
@ -313,7 +312,7 @@ class TestingMeanScaleGetter(unittest.TestCase):
for input in exp_res.keys():
for key in exp_res[input].keys():
if type(exp_res[input][key]) is np.ndarray:
npt.assert_array_equal(exp_res[input][key], result[input][key])
assert np.array_equal(exp_res[input][key], result[input][key])
else:
self.assertEqual(exp_res[input][key], result[input][key])
@ -335,7 +334,7 @@ class TestingMeanScaleGetter(unittest.TestCase):
for input in exp_res.keys():
for key in exp_res[input].keys():
if type(exp_res[input][key]) is np.ndarray:
npt.assert_array_equal(exp_res[input][key], result[input][key])
assert np.array_equal(exp_res[input][key], result[input][key])
else:
self.assertEqual(exp_res[input][key], result[input][key])
@ -355,7 +354,7 @@ class TestingMeanScaleGetter(unittest.TestCase):
]
for i in range(0, len(exp_res)):
for j in range(0, len(exp_res[i])):
npt.assert_array_equal(exp_res[i][j], result[i][j])
assert np.array_equal(exp_res[i][j], result[i][j])
def test_scale_do_not_match_input(self):
scale_values = parse_tuple_pairs("input_not_present(255),input2(255)")
@ -376,7 +375,7 @@ class TestingMeanScaleGetter(unittest.TestCase):
self.assertEqual(len(exp_res), len(res_values))
for i, j in zip(exp_res, res_values):
self.assertEqual(i, j)
npt.assert_array_equal(exp_res[i], res_values[j])
assert np.array_equal(exp_res[i], res_values[j])
def test_input_without_values(self):
self.assertRaises(Error, parse_tuple_pairs, "input1,input2")
@ -452,7 +451,7 @@ class TestShapesParsing(unittest.TestCase):
exp_res = {'inp1': np.array([1, 22, 333, 123]), 'inp2': np.array([-1, 45, 7, 1])}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_get_shapes_several_inputs_several_shapes2(self):
# shapes specified using --input command line parameter and no values
@ -461,13 +460,45 @@ class TestShapesParsing(unittest.TestCase):
exp_res = {'inp1': np.array([1, 22, 333, 123]), 'inp2': np.array([-1, 45, 7, 1])}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
placeholder_values_res, input_node_names_res = get_freeze_placeholder_values(argv_input, None)
placeholder_values_ref = {}
input_node_names_ref = "inp1,inp2"
self.assertEqual(list(placeholder_values_res.keys()), list(placeholder_values_ref.keys()))
for i in placeholder_values_ref.keys():
npt.assert_array_equal(placeholder_values_res[i], placeholder_values_ref[i])
assert np.array_equal(placeholder_values_res[i], placeholder_values_ref[i])
def test_get_shapes_and_freezing_with_scalar_and_without_shapes_in_input(self):
# shapes and value for freezing specified using --input command line parameter
argv_input = "inp1,inp2->157"
result_shapes, _ = get_placeholder_shapes(argv_input, None)
ref_shapes = {'inp1': None, 'inp2': None}
self.assertEqual(list(ref_shapes.keys()), list(result_shapes.keys()))
for i in ref_shapes.keys():
assert np.array_equal(result_shapes[i], ref_shapes[i])
placeholder_values_res, input_node_names_res = get_freeze_placeholder_values(argv_input, None)
placeholder_values_ref = {'inp2': 157}
self.assertEqual(list(placeholder_values_res.keys()), list(placeholder_values_ref.keys()))
for i in placeholder_values_ref.keys():
self.assertEqual(placeholder_values_res[i], placeholder_values_ref[i])
def test_get_shapes_and_freezing_with_scalar(self):
# shapes and value for freezing specified using --input command line parameter
argv_input = "inp1,inp2[]->157"
result_shapes, _ = get_placeholder_shapes(argv_input, None)
ref_shapes = {'inp1': None, 'inp2': ()}
self.assertEqual(list(ref_shapes.keys()), list(result_shapes.keys()))
for i in ref_shapes.keys():
assert np.array_equal(result_shapes[i], ref_shapes[i])
placeholder_values_res, input_node_names_res = get_freeze_placeholder_values(argv_input, None)
placeholder_values_ref = {'inp2': 157}
self.assertEqual(list(placeholder_values_res.keys()), list(placeholder_values_ref.keys()))
for i in placeholder_values_ref.keys():
self.assertEqual(placeholder_values_res[i], placeholder_values_ref[i])
def test_get_shapes_several_inputs_several_shapes3(self):
# shapes and value for freezing specified using --input command line parameter
@ -476,14 +507,14 @@ class TestShapesParsing(unittest.TestCase):
exp_res = {'inp1': np.array([3, 1]), 'inp2': np.array([3, 2, 3]), 'inp3': np.array([5])}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
placeholder_values_res, input_node_names_res = get_freeze_placeholder_values(argv_input, None)
placeholder_values_ref = {'inp1': np.array(['1.0', '2.0', '3.0']),
'inp3': np.array(['1.0', '1.0', '2.0', '3.0', '5.0'])}
input_node_names_ref = "inp1,inp2,inp3"
self.assertEqual(list(placeholder_values_res.keys()), list(placeholder_values_ref.keys()))
for i in placeholder_values_ref.keys():
npt.assert_array_equal(placeholder_values_res[i], placeholder_values_ref[i])
assert np.array_equal(placeholder_values_res[i], placeholder_values_ref[i])
def test_get_shapes_several_inputs_several_shapes4(self):
# shapes specified using --input_shape and values for freezing using --input command line parameter
@ -493,14 +524,14 @@ class TestShapesParsing(unittest.TestCase):
exp_res = {'inp1': np.array([3, 1]), 'inp2': np.array([3, 2, 3]), 'inp3': np.array([5])}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
placeholder_values_res, input_node_names_res = get_freeze_placeholder_values(argv_input, None)
placeholder_values_ref = {'inp1': np.array(['1.0', '2.0', '3.0']),
'inp3': np.array(['1.0', '1.0', '2.0', '3.0', '5.0'])}
input_node_names_ref = "inp1,inp2,inp3"
self.assertEqual(list(placeholder_values_res.keys()), list(placeholder_values_ref.keys()))
for i in placeholder_values_ref.keys():
npt.assert_array_equal(placeholder_values_res[i], placeholder_values_ref[i])
assert np.array_equal(placeholder_values_res[i], placeholder_values_ref[i])
self.assertEqual(input_node_names_ref, input_node_names_res)
def test_get_shapes_several_inputs_several_shapes5(self):
@ -513,7 +544,7 @@ class TestShapesParsing(unittest.TestCase):
exp_res = {'inp1': np.array([3, 1]), 'inp2': np.array([3, 2, 3]), 'inp3': np.array([5])}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
placeholder_values_res, input_node_names_res = get_freeze_placeholder_values(argv_input,
argv_freeze_placeholder_with_value)
placeholder_values_ref = {'inp1': np.array(['1.0', '2.0', '3.0']),
@ -522,22 +553,22 @@ class TestShapesParsing(unittest.TestCase):
input_node_names_ref = "inp1,inp2,inp3"
self.assertEqual(sorted(list(placeholder_values_res.keys())), sorted(list(placeholder_values_ref.keys())))
for i in placeholder_values_ref.keys():
npt.assert_array_equal(placeholder_values_res[i], placeholder_values_ref[i])
assert np.array_equal(placeholder_values_res[i], placeholder_values_ref[i])
self.assertEqual(input_node_names_ref, input_node_names_res)
def test_get_shapes_several_inputs_several_shapes6(self):
# 0D value for freezing specified using --input command line parameter without shape
argv_input = "inp1[3 1]->[1.0 2.0 3.0],inp2[3 2 3],inp3->False"
result, _ = get_placeholder_shapes(argv_input, None)
exp_res = {'inp1': np.array([3, 1]), 'inp2': np.array([3, 2, 3]), 'inp3': np.array(False).shape}
exp_res = {'inp1': np.array([3, 1]), 'inp2': np.array([3, 2, 3]), 'inp3': None}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
placeholder_values_res, input_node_names_res = get_freeze_placeholder_values(argv_input, None)
placeholder_values_ref = {'inp1': np.array(['1.0', '2.0', '3.0']), 'inp3': False}
self.assertEqual(list(placeholder_values_res.keys()), list(placeholder_values_ref.keys()))
for i in placeholder_values_ref.keys():
npt.assert_array_equal(placeholder_values_res[i], placeholder_values_ref[i])
assert np.array_equal(placeholder_values_res[i], placeholder_values_ref[i])
def test_get_shapes_several_inputs_several_shapes7(self):
# 0D shape and value for freezing specified using --input command line parameter
@ -546,12 +577,12 @@ class TestShapesParsing(unittest.TestCase):
exp_res = {'inp1': np.array([3, 1]), 'inp2': np.array([3, 2, 3]), 'inp3': np.array(False).shape}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
placeholder_values_res, input_node_names_res = get_freeze_placeholder_values(argv_input, None)
placeholder_values_ref = {'inp1': np.array(['1.0', '2.0', '3.0']), 'inp3': True}
self.assertEqual(list(placeholder_values_res.keys()), list(placeholder_values_ref.keys()))
for i in placeholder_values_ref.keys():
npt.assert_array_equal(placeholder_values_res[i], placeholder_values_ref[i])
assert np.array_equal(placeholder_values_res[i], placeholder_values_ref[i])
def test_get_shapes_and_data_types1(self):
argv_input = "inp1[3 1]->[1.0 2.0 3.0],inp2[3 2 3]{i32},inp3[5]{f32}->[1.0 1.0 2.0 3.0 5.0]"
@ -560,7 +591,7 @@ class TestShapesParsing(unittest.TestCase):
ref_result_data_types = {'inp2': np.int32, 'inp3': np.float32}
self.assertEqual(list(ref_result_shapes.keys()), list(result_shapes.keys()))
for i in ref_result_shapes.keys():
npt.assert_array_equal(result_shapes[i], ref_result_shapes[i])
assert np.array_equal(result_shapes[i], ref_result_shapes[i])
self.assertEqual(list(ref_result_data_types.keys()), list(result_data_types.keys()))
for i in ref_result_data_types.keys():
np.testing.assert_equal(result_data_types[i], ref_result_data_types[i])
@ -572,7 +603,7 @@ class TestShapesParsing(unittest.TestCase):
ref_result_data_types = {'inp2': np.int32, '0:inp3': np.float32}
self.assertEqual(list(ref_result_shapes.keys()), list(result_shapes.keys()))
for i in ref_result_shapes.keys():
npt.assert_array_equal(result_shapes[i], ref_result_shapes[i])
assert np.array_equal(result_shapes[i], ref_result_shapes[i])
self.assertEqual(list(ref_result_data_types.keys()), list(result_data_types.keys()))
for i in ref_result_data_types.keys():
np.testing.assert_equal(result_data_types[i], ref_result_data_types[i])
@ -584,7 +615,7 @@ class TestShapesParsing(unittest.TestCase):
ref_result_data_types = {'inp2': np.int32, 'inp3:4': np.float32}
self.assertEqual(list(ref_result_shapes.keys()), list(result_shapes.keys()))
for i in ref_result_shapes.keys():
npt.assert_array_equal(result_shapes[i], ref_result_shapes[i])
assert np.array_equal(result_shapes[i], ref_result_shapes[i])
self.assertEqual(list(ref_result_data_types.keys()), list(result_data_types.keys()))
for i in ref_result_data_types.keys():
np.testing.assert_equal(result_data_types[i], ref_result_data_types[i])
@ -597,7 +628,7 @@ class TestShapesParsing(unittest.TestCase):
ref_result_data_types = {}
self.assertEqual(list(ref_result_shapes.keys()), list(result_shapes.keys()))
for i in ref_result_shapes.keys():
npt.assert_array_equal(result_shapes[i], ref_result_shapes[i])
assert np.array_equal(result_shapes[i], ref_result_shapes[i])
self.assertEqual(list(ref_result_data_types.keys()), list(result_data_types.keys()))
for i in ref_result_data_types.keys():
np.testing.assert_equal(result_data_types[i], ref_result_data_types[i])
@ -610,7 +641,7 @@ class TestShapesParsing(unittest.TestCase):
ref_result_data_types = {}
self.assertEqual(list(ref_result_shapes.keys()), list(result_shapes.keys()))
for i in ref_result_shapes.keys():
npt.assert_array_equal(result_shapes[i], ref_result_shapes[i])
assert np.array_equal(result_shapes[i], ref_result_shapes[i])
self.assertEqual(list(ref_result_data_types.keys()), list(result_data_types.keys()))
for i in ref_result_data_types.keys():
np.testing.assert_equal(result_data_types[i], ref_result_data_types[i])
@ -623,7 +654,7 @@ class TestShapesParsing(unittest.TestCase):
ref_result_data_types = {'placeholder1': np.int32, 'placeholder3': np.int32}
self.assertEqual(list(ref_result_shapes.keys()), list(result_shapes.keys()))
for i in ref_result_shapes.keys():
npt.assert_array_equal(result_shapes[i], ref_result_shapes[i])
assert np.array_equal(result_shapes[i], ref_result_shapes[i])
self.assertEqual(list(ref_result_data_types.keys()), list(result_data_types.keys()))
for i in ref_result_data_types.keys():
np.testing.assert_equal(result_data_types[i], ref_result_data_types[i])
@ -672,28 +703,28 @@ class TestShapesParsing(unittest.TestCase):
exp_res = {'inp1': np.array([1, 22, 333, 123])}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_get_shapes_no_input_no_shape(self):
argv_input = ""
input_shapes = ""
result, _ = get_placeholder_shapes(argv_input, input_shapes)
exp_res = np.array([None])
npt.assert_array_equal(result, exp_res)
exp_res = None
assert np.array_equal(result, exp_res)
def test_get_shapes_no_input_one_shape(self):
argv_input = ""
input_shapes = "(12,4,1)"
result, _ = get_placeholder_shapes(argv_input, input_shapes)
exp_res = np.array([12, 4, 1])
npt.assert_array_equal(result, exp_res)
assert np.array_equal(result, exp_res)
def test_get_shapes_no_input_one_shape2(self):
argv_input = ""
input_shapes = "[12,4,1]"
result, _ = get_placeholder_shapes(argv_input, input_shapes)
exp_res = np.array([12, 4, 1])
npt.assert_array_equal(result, exp_res)
assert np.array_equal(result, exp_res)
def test_get_shapes_no_input_two_shapes(self):
argv_input = ""
@ -704,10 +735,10 @@ class TestShapesParsing(unittest.TestCase):
argv_input = "inp1"
input_shapes = ""
result, _ = get_placeholder_shapes(argv_input, input_shapes)
exp_res = {'inp1': np.array([None])}
exp_res = {'inp1': None}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_get_shapes_one_input_wrong_shape8(self):
argv_input = "inp1"
@ -766,7 +797,7 @@ class TestShapesParsing(unittest.TestCase):
exp_res = {'inp1': np.array([-1, 4, 1]), 'inp2': np.array([4, 6, 8])}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_get_shapes_one_input_first_neg_shape_not_one(self):
argv_input = "inp1"
@ -791,7 +822,7 @@ class TestShapesParsing(unittest.TestCase):
exp_res = {'inp1': (1, (0, 22), (1, 100), -1), 'inp2': (-1, (45, np.iinfo(np.int64).max), 7, 1)}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_get_shapes_several_inputs_several_partial_shapes2(self):
# shapes specified using --input command line parameter and no values
@ -800,44 +831,44 @@ class TestShapesParsing(unittest.TestCase):
exp_res = {'inp1': (1, -1, (50, 100), 123), 'inp2': (-1, (45,np.iinfo(np.int64).max), (0, 7), 1)}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
placeholder_values_res, input_node_names_res = get_freeze_placeholder_values(argv_input, None)
placeholder_values_ref = {}
input_node_names_ref = "inp1,inp2"
self.assertEqual(list(placeholder_values_res.keys()), list(placeholder_values_ref.keys()))
for i in placeholder_values_ref.keys():
npt.assert_array_equal(placeholder_values_res[i], placeholder_values_ref[i])
assert np.array_equal(placeholder_values_res[i], placeholder_values_ref[i])
def test_get_shapes_several_inputs_several_partial_shapes3(self):
# shapes and value for freezing specified using --input command line parameter
argv_input = "inp1[3 1]->[1.0 2.0 3.0],inp2[3.. ..2 5..10 ? -1],inp3[5]->[1.0 1.0 2.0 3.0 5.0]"
result, _ = get_placeholder_shapes(argv_input, None)
exp_res = {'inp1': (3, 1), 'inp2': ((3, np.iinfo(np.int64).max), (0, 2), (5, 10), -1, -1), 'inp3': (5)}
exp_res = {'inp1': (3, 1), 'inp2': ((3, np.iinfo(np.int64).max), (0, 2), (5, 10), -1, -1), 'inp3': (5,)}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
placeholder_values_res, input_node_names_res = get_freeze_placeholder_values(argv_input, None)
placeholder_values_ref = {'inp1': np.array(['1.0', '2.0', '3.0']), 'inp3': np.array(['1.0', '1.0', '2.0', '3.0', '5.0'])}
input_node_names_ref = "inp1,inp2,inp3"
self.assertEqual(list(placeholder_values_res.keys()), list(placeholder_values_ref.keys()))
for i in placeholder_values_ref.keys():
npt.assert_array_equal(placeholder_values_res[i], placeholder_values_ref[i])
assert np.array_equal(placeholder_values_res[i], placeholder_values_ref[i])
def test_get_shapes_several_inputs_several_partial_shapes4(self):
# shapes specified using --input_shape and values for freezing using --input command line parameter
argv_input = "inp1->[1.0 2.0 3.0],inp2,inp3->[1.0 1.0 2.0 3.0 5.0]"
input_shapes = "(3,1), (3..,..2,5..10,?,-1), (5)"
result, _ = get_placeholder_shapes(argv_input, input_shapes)
exp_res = {'inp1': (3, 1), 'inp2': ((3, np.iinfo(np.int64).max), (0, 2), (5, 10), -1, -1), 'inp3': (5)}
exp_res = {'inp1': (3, 1), 'inp2': ((3, np.iinfo(np.int64).max), (0, 2), (5, 10), -1, -1), 'inp3': (5,)}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
placeholder_values_res, input_node_names_res = get_freeze_placeholder_values(argv_input, None)
placeholder_values_ref = {'inp1': np.array(['1.0', '2.0', '3.0']), 'inp3': np.array(['1.0', '1.0', '2.0', '3.0', '5.0'])}
input_node_names_ref = "inp1,inp2,inp3"
self.assertEqual(list(placeholder_values_res.keys()), list(placeholder_values_ref.keys()))
for i in placeholder_values_ref.keys():
npt.assert_array_equal(placeholder_values_res[i], placeholder_values_ref[i])
assert np.array_equal(placeholder_values_res[i], placeholder_values_ref[i])
self.assertEqual(input_node_names_ref, input_node_names_res)
def test_get_shapes_several_inputs_several_partial_shapes5(self):
@ -847,32 +878,32 @@ class TestShapesParsing(unittest.TestCase):
argv_freeze_placeholder_with_value = "inp2->[5.0 7.0 3.0],inp4->[100.0 200.0]"
result, _ = get_placeholder_shapes(argv_input, input_shapes)
exp_res = {'inp1': (3, 1), 'inp2': ((3, np.iinfo(np.int64).max), (0, 2), (5, 10), -1, -1), 'inp3': (5)}
exp_res = {'inp1': (3, 1), 'inp2': ((3, np.iinfo(np.int64).max), (0, 2), (5, 10), -1, -1), 'inp3': (5,)}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
placeholder_values_res, input_node_names_res = get_freeze_placeholder_values(argv_input, argv_freeze_placeholder_with_value)
placeholder_values_ref = {'inp1': np.array(['1.0', '2.0', '3.0']), 'inp3': np.array(['1.0', '1.0', '2.0', '3.0', '5.0'],),
'inp2': np.array(['5.0', '7.0', '3.0']), 'inp4': np.array(['100.0', '200.0'])}
input_node_names_ref = "inp1,inp2,inp3"
self.assertEqual(sorted(list(placeholder_values_res.keys())), sorted(list(placeholder_values_ref.keys())))
for i in placeholder_values_ref.keys():
npt.assert_array_equal(placeholder_values_res[i], placeholder_values_ref[i])
assert np.array_equal(placeholder_values_res[i], placeholder_values_ref[i])
self.assertEqual(input_node_names_ref, input_node_names_res)
def test_get_shapes_several_inputs_several_partial_shapes6(self):
# 0D value for freezing specified using --input command line parameter without shape
argv_input = "inp1[3 1]->[1.0 2.0 3.0],inp2[3.. ..2 5..10 ? -1],inp3->False"
result, _ = get_placeholder_shapes(argv_input, None)
exp_res = {'inp1': (3, 1), 'inp2': ((3, np.iinfo(np.int64).max), (0, 2), (5, 10), -1, -1), 'inp3': np.array(False).shape}
exp_res = {'inp1': (3, 1), 'inp2': ((3, np.iinfo(np.int64).max), (0, 2), (5, 10), -1, -1), 'inp3': None}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
placeholder_values_res, input_node_names_res = get_freeze_placeholder_values(argv_input, None)
placeholder_values_ref = {'inp1': np.array(['1.0', '2.0', '3.0']), 'inp3': False}
self.assertEqual(list(placeholder_values_res.keys()), list(placeholder_values_ref.keys()))
for i in placeholder_values_ref.keys():
npt.assert_array_equal(placeholder_values_res[i], placeholder_values_ref[i])
assert np.array_equal(placeholder_values_res[i], placeholder_values_ref[i])
def test_get_shapes_several_inputs_several_partial_shapes7(self):
# 0D shape and value for freezing specified using --input command line parameter
@ -881,12 +912,12 @@ class TestShapesParsing(unittest.TestCase):
exp_res = {'inp1': (3, 1), 'inp2': ((3, np.iinfo(np.int64).max), (0, 2), (5, 10), -1, -1), 'inp3': np.array(False).shape}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
placeholder_values_res, input_node_names_res = get_freeze_placeholder_values(argv_input, None)
placeholder_values_ref = {'inp1': np.array(['1.0', '2.0', '3.0']), 'inp3': True}
self.assertEqual(list(placeholder_values_res.keys()), list(placeholder_values_ref.keys()))
for i in placeholder_values_ref.keys():
npt.assert_array_equal(placeholder_values_res[i], placeholder_values_ref[i])
assert np.array_equal(placeholder_values_res[i], placeholder_values_ref[i])
def test_get_shapes_and_data_types_partial_shape_with_input_port(self):
argv_input = "inp1:1[3 1]->[1.0 2.0 3.0],0:inp2[3.. ..2 5..10 ? -1]{i32},inp3:4[5]{f32}->[1.0 1.0 2.0 3.0 5.0]"
@ -895,7 +926,7 @@ class TestShapesParsing(unittest.TestCase):
ref_result_data_types = {'0:inp2': np.int32, 'inp3:4': np.float32}
self.assertEqual(list(ref_result_shapes.keys()), list(result_shapes.keys()))
for i in ref_result_shapes.keys():
npt.assert_array_equal(result_shapes[i], ref_result_shapes[i])
assert np.array_equal(result_shapes[i], ref_result_shapes[i])
self.assertEqual(list(ref_result_data_types.keys()), list(result_data_types.keys()))
for i in ref_result_data_types.keys():
np.testing.assert_equal(result_data_types[i], ref_result_data_types[i])
@ -907,7 +938,7 @@ class TestShapesParsing(unittest.TestCase):
ref_result_data_types = {'inp2:3': np.int32, 'inp3:4': np.float32}
self.assertEqual(list(ref_result_shapes.keys()), list(result_shapes.keys()))
for i in ref_result_shapes.keys():
npt.assert_array_equal(result_shapes[i], ref_result_shapes[i])
assert np.array_equal(result_shapes[i], ref_result_shapes[i])
self.assertEqual(list(ref_result_data_types.keys()), list(result_data_types.keys()))
for i in ref_result_data_types.keys():
np.testing.assert_equal(result_data_types[i], ref_result_data_types[i])
@ -1137,7 +1168,7 @@ class TestLayoutParsing(unittest.TestCase):
'name2': {'source_layout': '[n,h,w,c]', 'target_layout': '[n,c,h,w]'}}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_get_layout_2(self):
argv_layout = "name1(nhwc),name2(nhwc->nchw)"
@ -1146,7 +1177,7 @@ class TestLayoutParsing(unittest.TestCase):
'name2': {'source_layout': 'nhwc', 'target_layout': 'nchw'}}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_get_layout_3(self):
argv_layout = "name1(n...c),name2(n...c->nc...)"
@ -1155,7 +1186,7 @@ class TestLayoutParsing(unittest.TestCase):
'name2': {'source_layout': 'n...c', 'target_layout': 'nc...'}}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_get_layout_4(self):
argv_layout = "nhwc"
@ -1163,7 +1194,7 @@ class TestLayoutParsing(unittest.TestCase):
exp_res = {'': {'source_layout': 'nhwc', 'target_layout': None}}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_get_layout_5(self):
argv_layout = "[n,h,w,c]"
@ -1171,7 +1202,7 @@ class TestLayoutParsing(unittest.TestCase):
exp_res = {'': {'source_layout': '[n,h,w,c]', 'target_layout': None}}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_get_layout_6(self):
argv_layout = "nhwc->nchw"
@ -1179,7 +1210,7 @@ class TestLayoutParsing(unittest.TestCase):
exp_res = {'': {'source_layout': 'nhwc', 'target_layout': 'nchw'}}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_get_layout_7(self):
argv_layout = "[n,h,w,c]->[n,c,h,w]"
@ -1187,7 +1218,7 @@ class TestLayoutParsing(unittest.TestCase):
exp_res = {'': {'source_layout': '[n,h,w,c]', 'target_layout': '[n,c,h,w]'}}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_get_layout_scalar(self):
argv_layout = "name1(nhwc),name2([])"
@ -1196,7 +1227,7 @@ class TestLayoutParsing(unittest.TestCase):
'name2': {'source_layout': '[]', 'target_layout': None}}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_get_layout_source_layout_1(self):
argv_source_layout = "[n,h,w,c]"
@ -1204,7 +1235,7 @@ class TestLayoutParsing(unittest.TestCase):
exp_res = {'': {'source_layout': '[n,h,w,c]', 'target_layout': None}}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_get_layout_source_layout_2(self):
argv_source_layout = "nhwc"
@ -1212,7 +1243,7 @@ class TestLayoutParsing(unittest.TestCase):
exp_res = {'': {'source_layout': 'nhwc', 'target_layout': None}}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_get_layout_source_layout_3(self):
argv_source_layout = "name1(nhwc),name2(nchw)"
@ -1221,7 +1252,7 @@ class TestLayoutParsing(unittest.TestCase):
'name2': {'source_layout': 'nchw', 'target_layout': None}}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_get_layout_source_layout_4(self):
argv_source_layout = "name1([n,h,w,c]),name2([n,c,h,w])"
@ -1230,7 +1261,7 @@ class TestLayoutParsing(unittest.TestCase):
'name2': {'source_layout': '[n,c,h,w]', 'target_layout': None}}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_get_layout_source_layout_5(self):
argv_source_layout = "name1(nhwc),name2([n,c,h,w])"
@ -1239,7 +1270,7 @@ class TestLayoutParsing(unittest.TestCase):
'name2': {'source_layout': '[n,c,h,w]', 'target_layout': None}}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_get_layout_source_layout_6(self):
argv_source_layout = "name1(nhwc),name2[n,c,h,w]"
@ -1248,7 +1279,7 @@ class TestLayoutParsing(unittest.TestCase):
'name2': {'source_layout': '[n,c,h,w]', 'target_layout': None}}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_get_layout_source_layout_scalar(self):
argv_source_layout = "name1(nhwc),name2([])"
@ -1257,7 +1288,7 @@ class TestLayoutParsing(unittest.TestCase):
'name2': {'source_layout': '[]', 'target_layout': None}}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_get_layout_target_layout_1(self):
argv_target_layout = "[n,h,w,c]"
@ -1265,7 +1296,7 @@ class TestLayoutParsing(unittest.TestCase):
exp_res = {'': {'source_layout': None, 'target_layout': '[n,h,w,c]'}}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_get_layout_target_layout_2(self):
argv_target_layout = "nhwc"
@ -1273,7 +1304,7 @@ class TestLayoutParsing(unittest.TestCase):
exp_res = {'': {'source_layout': None, 'target_layout': 'nhwc'}}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_get_layout_target_layout_3(self):
argv_target_layout = "name1(nhwc),name2(nchw)"
@ -1282,7 +1313,7 @@ class TestLayoutParsing(unittest.TestCase):
'name2': {'source_layout': None, 'target_layout': 'nchw'}}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_get_layout_target_layout_4(self):
argv_target_layout = "name1([n,h,w,c]),name2([n,c,h,w])"
@ -1291,7 +1322,7 @@ class TestLayoutParsing(unittest.TestCase):
'name2': {'source_layout': None, 'target_layout': '[n,c,h,w]'}}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_get_layout_target_layout_5(self):
argv_target_layout = "name1(nhwc),name2([n,c,h,w])"
@ -1300,7 +1331,7 @@ class TestLayoutParsing(unittest.TestCase):
'name2': {'source_layout': None, 'target_layout': '[n,c,h,w]'}}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_get_layout_target_layout_6(self):
argv_target_layout = "name1(nhwc),name2[n,c,h,w]"
@ -1309,7 +1340,7 @@ class TestLayoutParsing(unittest.TestCase):
'name2': {'source_layout': None, 'target_layout': '[n,c,h,w]'}}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_get_layout_target_layout_scalar(self):
argv_target_layout = "name1(nhwc),name2[]"
@ -1318,7 +1349,7 @@ class TestLayoutParsing(unittest.TestCase):
'name2': {'source_layout': None, 'target_layout': '[]'}}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_get_layout_source_target_layout_1(self):
argv_source_layout = "[n,h,w,c]"
@ -1327,7 +1358,7 @@ class TestLayoutParsing(unittest.TestCase):
exp_res = {'': {'source_layout': '[n,h,w,c]', 'target_layout': '[n,c,h,w]'}}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_get_layout_source_target_layout_2(self):
argv_source_layout = "nhwc"
@ -1336,7 +1367,7 @@ class TestLayoutParsing(unittest.TestCase):
exp_res = {'': {'source_layout': 'nhwc', 'target_layout': 'nchw'}}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_get_layout_source_target_layout_3(self):
argv_source_layout = "name1(nhwc),name2(nhwc)"
@ -1346,7 +1377,7 @@ class TestLayoutParsing(unittest.TestCase):
'name2': {'source_layout': 'nhwc', 'target_layout': 'nchw'}}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_get_layout_source_target_layout_4(self):
argv_source_layout = "name1([n,h,w,c]),name2([n,h,w,c])"
@ -1356,7 +1387,7 @@ class TestLayoutParsing(unittest.TestCase):
'name2': {'source_layout': '[n,h,w,c]', 'target_layout': '[n,c,h,w]'}}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_get_layout_source_target_layout_5(self):
argv_source_layout = "name1(nhwc),name2[n,h,w,c]"
@ -1366,7 +1397,7 @@ class TestLayoutParsing(unittest.TestCase):
'name2': {'source_layout': '[n,h,w,c]', 'target_layout': '[n,c,h,w]'}}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_get_layout_source_target_layout_scalar(self):
argv_source_layout = "name1(nhwc),name2[]"
@ -1376,7 +1407,7 @@ class TestLayoutParsing(unittest.TestCase):
'name2': {'source_layout': '[]', 'target_layout': '[]'}}
self.assertEqual(list(exp_res.keys()), list(result.keys()))
for i in exp_res.keys():
npt.assert_array_equal(result[i], exp_res[i])
assert np.array_equal(result[i], exp_res[i])
def test_get_layout_raises_if_layout_and_source_layout_provided(self):
argv_layout = "nhwc"