Publishing 2019 R1 content
[platform/upstream/dldt.git] / model-optimizer / extensions / back / disable_unsupported_ND_operations.py
1 """
2  Copyright (c) 2018-2019 Intel Corporation
3
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
7
8       http://www.apache.org/licenses/LICENSE-2.0
9
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.
15 """
16
17 import networkx as nx
18
19 from mo.back.replacement import BackReplacementPattern
20 from mo.graph.graph import Node, Graph
21 from mo.utils.error import Error
22
23
24 class DisableUnsupportedNDOperations(BackReplacementPattern):
25     """
26         This pass disables ND Convolutions/Deconvolutions/Poolings
27     """
28     enabled = False
29
30     unsupported_operations = ['Convolution', 'Deconvolution', 'Pooling']
31
32     def find_and_replace_pattern(self, graph: Graph):
33         unsupported_nodes = []
34         for node in graph.nodes():
35             node = Node(graph, node)
36             if node.kind == 'op' and node.soft_get('type') in self.unsupported_operations:
37                 input_shape = node.in_node(0).shape
38                 if len(input_shape) > 4:
39                     unsupported_nodes.append((node.id, node.type))
40
41         if len(unsupported_nodes) == 0:
42             return
43
44         error_message = "\nOperations below were marked as unsupported due to they expect more than two spatial dims" \
45                         " (input shape length more than 4)\n"
46         error_message += "List of unsupported operations ({})\n".format(len(unsupported_nodes))
47         for node, type in unsupported_nodes:
48             error_message += "      {} {}\n".format(type, node)
49
50         raise Error(error_message)