2 Copyright (c) 2018-2019 Intel Corporation
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
17 from mo.back.replacement import BackReplacementPattern
18 from mo.graph.graph import Graph
21 class KaldiRemoveMemoryOutputBackReplacementPattern(BackReplacementPattern):
28 ('memory_node', dict(op='Memory')),
29 ('data_node', dict(kind='data')),
30 ('op_output', dict(op='OpOutput'))
33 ('memory_node', 'data_node'),
34 ('data_node', 'op_output')
39 def replace_pattern(graph: Graph, match: dict):
41 Need to find the pattern: Memory -> Data -> OpOutput
43 It is needed to make Memory nodes appear in IR,
44 but they are output nodes by default and we remove the OpOutput node after each output memory.
46 DO NOT use graph clean up after it
47 otherwise Memory nodes would be removed as they are not on the path from input to output
52 Graph with loaded model.
54 Patterns which were found in graph structure.
56 memory = match['memory_node']
57 data = match['data_node']
59 graph.remove_edge(memory.id, data.id)
60 graph.remove_node(data.id)