Files
openvino/model-optimizer/extensions/back/remove_last_softmax_pattern.py

50 lines
1.7 KiB
Python
Raw Normal View History

2018-10-16 13:45:03 +03:00
"""
2019-04-12 18:25:53 +03:00
Copyright (c) 2018-2019 Intel Corporation
2018-10-16 13:45:03 +03:00
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 networkx as nx
from mo.back.replacement import BackReplacementPattern
2019-04-12 18:25:53 +03:00
from mo.graph.graph import Graph
from mo.middle.passes.eliminate import remove_op_node_with_data_node
2018-10-16 13:45:03 +03:00
class RemoveLastSoftMaxPattern(BackReplacementPattern):
# This replacer is intentionally disabled and must be called if the flag --remove_output_softmax was enabled
enabled = False
@staticmethod
def pattern():
return dict(
nodes=[
2019-04-12 18:25:53 +03:00
('softmax_node', dict(op='SoftMax')),
('softmax_data', dict(kind='data')),
2019-08-09 19:02:42 +03:00
('op_output', dict(op='Result'))
2018-10-16 13:45:03 +03:00
],
2019-04-12 18:25:53 +03:00
edges=[
('softmax_node', 'softmax_data'),
('softmax_data', 'op_output')
]
2018-11-23 16:19:43 +03:00
)
2018-10-16 13:45:03 +03:00
@staticmethod
2019-04-12 18:25:53 +03:00
def replace_pattern(graph: Graph, match: dict):
2018-10-16 13:45:03 +03:00
"""
2019-04-12 18:25:53 +03:00
Removes output SoftMax layer
:param graph: graph to operate on
:param match: dictionary with matched nodes
2018-10-16 13:45:03 +03:00
"""
2019-04-12 18:25:53 +03:00
if len(match['softmax_data'].out_nodes()) == 1:
remove_op_node_with_data_node(graph, match['softmax_node'])