From d71d7d46acb786b350d6462601bd77d43fdcf468 Mon Sep 17 00:00:00 2001 From: Michael Nosov Date: Fri, 28 May 2021 14:25:33 +0300 Subject: [PATCH] Fix some flake8 findings --- model-optimizer/mo/front_ng/extractor.py | 20 ++++++++++-------- .../mo/front_ng/frontendmanager_wrapper.py | 2 +- model-optimizer/mo/front_ng/pipeline.py | 2 +- model-optimizer/mo/front_ng/serialize.py | 2 +- ngraph/python/src/ngraph/__init__.py | 18 +++++++--------- .../tests/test_ngraph/test_frontendmanager.py | 21 ++++++------------- 6 files changed, 28 insertions(+), 37 deletions(-) diff --git a/model-optimizer/mo/front_ng/extractor.py b/model-optimizer/mo/front_ng/extractor.py index a1b0e8ff94f464..2be013fc9670c6 100644 --- a/model-optimizer/mo/front_ng/extractor.py +++ b/model-optimizer/mo/front_ng/extractor.py @@ -11,7 +11,7 @@ from mo.utils.error import Error -def fe_decodeNameWithPort (inputModel, node_name: str): +def fe_decodeNameWithPort(inputModel, node_name: str): """ Decode name with optional port specification w/o traversing all the nodes in the graph :param inputModel: Input Model @@ -39,15 +39,17 @@ def fe_decodeNameWithPort (inputModel, node_name: str): def fe_input_user_data_repack(inputModel, input_user_shapes: [None, list, dict, np.ndarray], - freeze_placeholder: dict, input_user_data_types = dict()): + freeze_placeholder: dict, input_user_data_types=dict()): """ - Restructures user input cutting request. Splits ports out of node names. Transforms node names to node ids. + Restructures user input cutting request. Splits ports out of node names. + Transforms node names to node ids. :param graph: graph to operate on :param input_user_shapes: data structure representing user input cutting request. It may be: # None value if user did not provide neither --input nor --input_shape keys - # list instance which contains input layer names with or without ports if user provided only --input key - # dict instance which contains input layer names with or without ports as keys and shapes as values if user - provided both --input and --input_shape + # list instance which contains input layer names with or without ports if user provided + only --input key + # dict instance which contains input layer names with or without ports as keys and shapes as + values if user provided both --input and --input_shape # np.ndarray if user provided only --input_shape key :param freeze_placeholder: dictionary with placeholder names as keys and freezing value as values :param input_user_data_types: dictionary with input nodes and its data types @@ -136,7 +138,7 @@ def fe_output_user_data_repack(inputModel, outputs: list): def fe_user_data_repack(inputModel, input_user_shapes: [None, list, dict, np.array], - input_user_data_types: dict, outputs: list, freeze_placeholder: dict): + input_user_data_types: dict, outputs: list, freeze_placeholder: dict): """ :param inputModel: Input Model to operate on :param input_user_shapes: data structure representing user input cutting request @@ -144,8 +146,8 @@ def fe_user_data_repack(inputModel, input_user_shapes: [None, list, dict, np.arr :param freeze_placeholder: dictionary with placeholder names as keys and freezing value as values :return: restructured input, output and freeze placeholder dictionaries or None values """ - _input_shapes, _freeze_placeholder = fe_input_user_data_repack(inputModel, input_user_shapes, freeze_placeholder, - input_user_data_types=input_user_data_types) + _input_shapes, _freeze_placeholder = fe_input_user_data_repack( + inputModel, input_user_shapes, freeze_placeholder, input_user_data_types=input_user_data_types) _outputs = fe_output_user_data_repack(inputModel, outputs) print('---------- Inputs/outpus/freezePlaceholder -----------') diff --git a/model-optimizer/mo/front_ng/frontendmanager_wrapper.py b/model-optimizer/mo/front_ng/frontendmanager_wrapper.py index cb1e0786017ad1..b8c2961ef64ad5 100644 --- a/model-optimizer/mo/front_ng/frontendmanager_wrapper.py +++ b/model-optimizer/mo/front_ng/frontendmanager_wrapper.py @@ -10,7 +10,7 @@ def create_fem(): fem = None try: - from ngraph.frontend import FrontEndManager # pylint: disable=no-name-in-module,import-error + from ngraph.frontend import FrontEndManager # pylint: disable=no-name-in-module,import-error fem = FrontEndManager() except Exception: print("nGraph FrontEndManager is not initialized") diff --git a/model-optimizer/mo/front_ng/pipeline.py b/model-optimizer/mo/front_ng/pipeline.py index f27c2186b2b270..669445083c072a 100644 --- a/model-optimizer/mo/front_ng/pipeline.py +++ b/model-optimizer/mo/front_ng/pipeline.py @@ -81,7 +81,7 @@ def compare_nodes(old, new): for i in range(oldPartShape.rank.get_length()): # Assume batch size is always 1-st dimension in shape # Keep other dimensions unchanged - newshape.append(Dimension(argv.batch) if i is 0 else oldPartShape.get_dimension(i)) + newshape.append(Dimension(argv.batch) if i == 0 else oldPartShape.get_dimension(i)) oldshape_converted.append(oldPartShape.get_dimension(i)) validate_batch_in_shape(oldshape_converted, joinedName) diff --git a/model-optimizer/mo/front_ng/serialize.py b/model-optimizer/mo/front_ng/serialize.py index 1c19a4b6ef9022..48ff887ad70912 100644 --- a/model-optimizer/mo/front_ng/serialize.py +++ b/model-optimizer/mo/front_ng/serialize.py @@ -8,7 +8,7 @@ def ngraph_emit_ir(nGraphFunction, argv: argparse.Namespace): output_dir = argv.output_dir if argv.output_dir != '.' else os.getcwd() - from ngraph import function_to_cnn # pylint: disable=no-name-in-module,import-error + from ngraph import function_to_cnn # pylint: disable=no-name-in-module,import-error network = function_to_cnn(nGraphFunction) orig_model_name = os.path.normpath(os.path.join(output_dir, argv.model_name)) diff --git a/ngraph/python/src/ngraph/__init__.py b/ngraph/python/src/ngraph/__init__.py index 518c12c94bc262..f51c5cea130510 100644 --- a/ngraph/python/src/ngraph/__init__.py +++ b/ngraph/python/src/ngraph/__init__.py @@ -11,25 +11,23 @@ except DistributionNotFound: __version__ = "0.0.0.dev0" -from ngraph.impl import Node -from ngraph.impl import PartialShape + from ngraph.impl import Dimension from ngraph.impl import Function - +from ngraph.impl import Node +from ngraph.impl import PartialShape +from ngraph.frontend import FrontEnd +from ngraph.frontend import FrontEndCapabilities +from ngraph.frontend import FrontEndManager +from ngraph.frontend import GeneralFailure from ngraph.frontend import NotImplementedFailure from ngraph.frontend import InitializationFailure +from ngraph.frontend import InputModel from ngraph.frontend import OpConversionFailure from ngraph.frontend import OpValidationFailure -from ngraph.frontend import GeneralFailure -from ngraph.frontend import FrontEndManager -from ngraph.frontend import FrontEndCapabilities -from ngraph.frontend import FrontEnd -from ngraph.frontend import InputModel from ngraph.frontend import Place - from ngraph.helpers import function_from_cnn from ngraph.helpers import function_to_cnn - from ngraph.opset7 import absolute from ngraph.opset7 import absolute as abs from ngraph.opset7 import acos diff --git a/ngraph/python/tests/test_ngraph/test_frontendmanager.py b/ngraph/python/tests/test_ngraph/test_frontendmanager.py index 2406f6ff4b7962..4e4d894455b5e5 100644 --- a/ngraph/python/tests/test_ngraph/test_frontendmanager.py +++ b/ngraph/python/tests/test_ngraph/test_frontendmanager.py @@ -17,7 +17,7 @@ def test_load_by_framework_caps(): frontEnds = fem.get_available_front_ends() assert frontEnds is not None - assert 'mock_py' in frontEnds + assert "mock_py" in frontEnds caps = [FrontEndCapabilities.DEFAULT, FrontEndCapabilities.CUT, FrontEndCapabilities.NAMES, @@ -28,7 +28,7 @@ def test_load_by_framework_caps(): stat = get_fe_stat(fe) assert cap == stat.load_flags for i in range(len(caps) - 1): - for j in range(i+1, len(caps)): + for j in range(i + 1, len(caps)): assert caps[i] != caps[j] @@ -40,7 +40,7 @@ def test_load_by_unknown_framework(): except InitializationFailure as exc: print(exc) else: - assert False + raise AssertionError("Unexpected exception.") def test_load_from_file(): @@ -49,7 +49,7 @@ def test_load_from_file(): model = fe.load_from_file("abc.bin") assert model is not None stat = get_fe_stat(fe) - assert 'abc.bin' in stat.load_paths + assert "abc.bin" in stat.load_paths def test_convert_model(): @@ -134,7 +134,7 @@ def test_model_get_place_by_operation_and_input_port(): model = init_model() for i in range(1, 10): name = str(i) - model.get_place_by_operation_and_input_port(operationName=name, inputPortIndex=i*2) + model.get_place_by_operation_and_input_port(operationName=name, inputPortIndex=i * 2) stat = get_mdl_stat(model) assert stat.get_place_by_operation_and_input_port == i assert stat.lastArgString == name @@ -145,7 +145,7 @@ def test_model_get_place_by_operation_and_output_port(): model = init_model() for i in range(1, 10): name = str(i) - model.get_place_by_operation_and_output_port(operationName=name, outputPortIndex=i*2) + model.get_place_by_operation_and_output_port(operationName=name, outputPortIndex=i * 2) stat = get_mdl_stat(model) assert stat.get_place_by_operation_and_output_port == i assert stat.lastArgString == name @@ -377,15 +377,6 @@ def test_place_is_equal_data(): assert stat.lastArgPlace == place2 -def test_place_is_equal_data(): - model, place = init_place() - place2 = model.get_place_by_tensor_name("2") - assert place.is_equal_data(other=place2) is not None - stat = get_place_stat(place) - assert stat.is_equal_data == 1 - assert stat.lastArgPlace == place2 - - def test_place_get_consuming_operations(): _, place = init_place() assert place.get_consuming_operations(outputPortIndex=22) is not None