Remove split-concat subgraph before pad op (#6506)
* Remove split-concat subgraph before pad op * Fix unit tests * Add unit tests for PadNormalizer * Fix according to review * add propagation up for Pad * Fix value propogation * Remove PadMormolizer * Refactoring according to review
This commit is contained in:
@@ -3,9 +3,10 @@
|
||||
|
||||
import unittest
|
||||
|
||||
from extensions.back.ReverseInputChannels import ReverseChannelsPropagationUp
|
||||
from extensions.back.ReverseInputChannels import ReverseChannelsPropagationUp, ReverseChannelsPropagationDown
|
||||
from mo.graph.graph import Node, Graph
|
||||
from unit_tests.utils.graph import build_graph, result, connect, regular_op_with_shaped_data
|
||||
from unit_tests.utils.graph import build_graph, result, connect, regular_op_with_shaped_data, valued_const_with_data
|
||||
from mo.front.common.partial_infer.utils import int64_array, float32_array
|
||||
|
||||
nodes = {
|
||||
**regular_op_with_shaped_data('placeholder1', [1, 3, 10, 10], {'type': 'Parameter'}),
|
||||
@@ -14,10 +15,25 @@ nodes = {
|
||||
**regular_op_with_shaped_data('mul', [1, 3, 10, 10], {'type': 'Multiply'}),
|
||||
**regular_op_with_shaped_data('reverse_channels', [1, 3, 10, 10], {'type': 'ReverseChannels', 'axis': 1}),
|
||||
|
||||
|
||||
**regular_op_with_shaped_data('pad', [1, 3, 10, 10], {'type': 'Pad'}),
|
||||
|
||||
**result('result'),
|
||||
}
|
||||
|
||||
|
||||
nodes2 = {
|
||||
**regular_op_with_shaped_data('placeholder', [1, 3, 10, 10], {'type': 'Parameter'}),
|
||||
|
||||
**valued_const_with_data('mul_const', float32_array([-127.5, -127.5, -127.5])),
|
||||
**regular_op_with_shaped_data('mul', [1, 3, 10, 10], {'type': 'Multiply'}),
|
||||
**valued_const_with_data('pad_const_1', int64_array([0, 0, 0, 0])),
|
||||
**valued_const_with_data('pad_const_2', int64_array([0, 0, 1, 1])),
|
||||
**regular_op_with_shaped_data('pad', [1, 3, 10, 10], {'type': 'Pad'}),
|
||||
**regular_op_with_shaped_data('reverse_channels', [1, 3, 10, 10], {'type': 'ReverseChannels', 'axis': 1}),
|
||||
**result('result'),
|
||||
}
|
||||
|
||||
class ReverseInputChannelsTest(unittest.TestCase):
|
||||
def check_graph_attrs(self, graph: Graph, parameter_node_names: list):
|
||||
for node in graph.get_op_nodes():
|
||||
@@ -47,3 +63,30 @@ class ReverseInputChannelsTest(unittest.TestCase):
|
||||
|
||||
ReverseChannelsPropagationUp.lift_up_through_eltwise(node, reverse_channels)
|
||||
self.check_graph_attrs(graph, ['placeholder1', 'placeholder2'])
|
||||
|
||||
def test_lift_up_through(self):
|
||||
graph = build_graph(nodes2, [*connect('placeholder', '0:mul'), *connect('mul_const', '1:mul'),
|
||||
*connect('mul', '0:pad'), *connect('pad_const_1', '1:pad'),
|
||||
*connect('pad_const_2', '2:pad'), *connect('pad', 'reverse_channels'),
|
||||
*connect('reverse_channels', 'result')])
|
||||
self.set_graph_attrs(graph, ['placeholder'])
|
||||
|
||||
node = Node(graph, 'pad')
|
||||
reverse_channels = Node(graph, 'reverse_channels')
|
||||
|
||||
ReverseChannelsPropagationUp.lift_up_through(node, reverse_channels)
|
||||
self.check_graph_attrs(graph, ['placeholder'])
|
||||
|
||||
|
||||
def test_pass_rc_through(self):
|
||||
graph = build_graph(nodes2, [*connect('placeholder', '0:mul'), *connect('mul_const', '1:mul'),
|
||||
*connect('mul', 'reverse_channels'), *connect('reverse_channels', '0:pad'),
|
||||
*connect('pad_const_1', '1:pad'), *connect('pad_const_2', '2:pad'),
|
||||
*connect('pad', 'result')])
|
||||
self.set_graph_attrs(graph, ['placeholder'])
|
||||
|
||||
node = Node(graph, 'pad')
|
||||
reverse_channels = Node(graph, 'reverse_channels')
|
||||
|
||||
ReverseChannelsPropagationDown.pass_rc_through(node, reverse_channels)
|
||||
self.check_graph_attrs(graph, ['placeholder'])
|
||||
|
||||
@@ -74,9 +74,7 @@ class PadTFToPadTest(unittest.TestCase):
|
||||
{}, nodes_with_edges_only=True)
|
||||
graph.get_op_nodes(op='TFPad')[0].add_input_port(2)
|
||||
|
||||
graph_ref = build_graph(nodes_attributes, common_edges + [('pad_fill', 'convert_like', {'in': 0, 'out': 0}),
|
||||
('placeholder', 'convert_like', {'in': 1, 'out': 0}),
|
||||
('convert_like', 'pad', {'in': 3, 'out': 0})],
|
||||
graph_ref = build_graph(nodes_attributes, common_edges,
|
||||
{}, nodes_with_edges_only=True)
|
||||
self._run_test(graph, graph_ref)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user