Skip to content

Commit

Permalink
Fix some flake8 findings
Browse files Browse the repository at this point in the history
  • Loading branch information
nosovmik committed May 28, 2021
1 parent 8d3ddf6 commit d71d7d4
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 37 deletions.
20 changes: 11 additions & 9 deletions model-optimizer/mo/front_ng/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -136,16 +138,16 @@ 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
:param outputs: list of node names to treat as outputs
: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 -----------')
Expand Down
2 changes: 1 addition & 1 deletion model-optimizer/mo/front_ng/frontendmanager_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion model-optimizer/mo/front_ng/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion model-optimizer/mo/front_ng/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
18 changes: 8 additions & 10 deletions ngraph/python/src/ngraph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 6 additions & 15 deletions ngraph/python/tests/test_ngraph/test_frontendmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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]


Expand All @@ -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():
Expand All @@ -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():
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d71d7d4

Please sign in to comment.