* Generate TensorIterator without back edges from TensorFlow models * Added a check in the MarkSubgraphsWithCorrectLayout to not fail when port is not connected * Updated the 'protobuf2nx' to consume the graph protobuf message * Cleanup TI from the IRv7 specific code * Do not run some front transformations recursively * Draft support for the ONNX Loop operation when 'cond' = True * LoopToTI transformation changes * Added draft of Loop operation and parser for ONNX Loop operation body * Updated Loop body parser + added shape and type infer for the Loop operation * Fixes for ONNX Loop operation parser * Moved Loop parsing to Loop op extractor. Added generation of external edges for the Loop body ops * Added support for ThresholdedRelu using decomposition * Added support for Min ONNX operation * Draft fixes for port_map generation for the Loop * Rename transformation file and fix BOM * Fixed shape inference for Loop scan outputs (axis is not None) * Fixed shape inference for ONNX Loop operation * Refactor checks in the TensorIteratorMerge transformation * Code refactoring. Enabled commented transformations * Documentation update for ONNX Loop, ThresholdedRelu and Min * Fixed typo in the Loop front transformation where execution condition input is connected. Other refactorings * Fixed in the Loop extractor * Added printing 'internal_layer_id' attribute in the graph dumper * Updated calculation of iterations number for the Loop * Added missing code * Fixed output port shapes and types generation for Loop operation * Update function names and variable names in the Loop operation * Fixed type inference for iteration count input * Added removal of input/output ports of the Loop if they are not used * Fixed renumbering Loop operations input/output ports to keep mandatory * Fixed ThresholdedReluDecomposition transformation * Updated MO IR Reader to know about Loop operation. But it is still not supported by the MO IR Reader * Added unit test for Slice op shape infer (reverse the sequence of elements) * Reverted changes in the ONNX loader function call to protobuf2nx * Enable Reshape0DToSqueeze transformation recursively * Refactored Loop operation support implementation * Changed ThresholdedReluDecomposition to generate Const with shape [1] instead of scalar * Code style and wording fixes * Restored accidentally removed 'return' statement in the TI shape infer function * Fixed comments * Fixed comment Co-authored-by: Evgeny Lazarev <elazarev.nnov@gmail.com>
61 lines
2.7 KiB
Python
61 lines
2.7 KiB
Python
"""
|
|
Copyright (C) 2020 Intel Corporation
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
"""
|
|
import unittest
|
|
|
|
from extensions.front.ThresholdedReluDecomposition import ThresholdedReluDecomposition
|
|
from mo.front.common.partial_infer.utils import float_array
|
|
from mo.utils.ir_engine.compare_graphs import compare_graphs
|
|
from mo.utils.unittest.graph import build_graph, const
|
|
|
|
nodes_attributes = {
|
|
'parameter': {'shape': None, 'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'},
|
|
'trelu': {'type': None, 'kind': 'op', 'op': 'ThresholdedRelu', 'alpha': 0.75, 'name': 'my_trelu'},
|
|
'result': {'type': 'Result', 'value': None, 'kind': 'op', 'op': 'Result'},
|
|
|
|
'cast': {'type': 'Convert', 'kind': 'op', 'op': 'Cast'},
|
|
'greater': {'type': 'Greater', 'kind': 'op', 'op': 'Greater'},
|
|
'mul': {'type': 'Multiply', 'kind': 'op', 'op': 'Mul', 'name': 'my_trelu'},
|
|
'squeeze2': {'type': 'Squeeze', 'kind': 'op', 'op': 'Squeeze'},
|
|
**const('alpha', float_array([0.75])),
|
|
}
|
|
|
|
|
|
class ThresholdedReluDecompositionTest(unittest.TestCase):
|
|
def test_trelu(self):
|
|
graph = build_graph(nodes_attributes,
|
|
[('parameter', 'trelu', {'in': 0, 'out': 0}),
|
|
('trelu', 'result', {'in': 0, 'out': 0}),
|
|
], nodes_with_edges_only=True)
|
|
|
|
graph_ref = build_graph(nodes_attributes,
|
|
[('parameter', 'greater', {'in': 0, 'out': 0}),
|
|
('alpha', 'greater', {'in': 1, 'out': 0}),
|
|
('greater', 'cast', {'in': 0, 'out': 0}),
|
|
('parameter', 'mul', {'in': 0, 'out': 0}),
|
|
('cast', 'mul', {'in': 1, 'out': 0}),
|
|
('mul', 'result', {'in': 0, 'out': 0}),
|
|
], nodes_with_edges_only=True)
|
|
|
|
graph.graph['layout'] = 'NCHW'
|
|
graph.stage = 'front'
|
|
|
|
ThresholdedReluDecomposition().find_and_replace_pattern(graph)
|
|
|
|
(flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True)
|
|
self.assertTrue(flag, resp)
|
|
self.assertTrue(len(graph.get_op_nodes(name='my_trelu')) == 1 and
|
|
graph.get_op_nodes(name='my_trelu')[0].op == 'Mul')
|