Publishing R3
[platform/upstream/dldt.git] / model-optimizer / extensions / front / onnx / transpose_ext.py
1 """
2  Copyright (c) 2018 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 import numpy as np
17 from mo.front.extractor import FrontExtractorOp
18 from mo.ops.op import Op
19 from mo.ops.permute import Permute
20
21 from mo.front.onnx.extractors.utils import onnx_attr
22
23
24 class TransposeFrontExtractor(FrontExtractorOp):
25     op = 'Transpose'
26     enabled = True
27
28     @staticmethod
29     def extract(node):
30         # In case of undefined 'perm' attribute, Transpose operation in ONNX reverse the dimensions
31         order = onnx_attr(node, 'perm', 'ints', default=None)
32         attrs = {
33             'order': np.array(order, dtype=np.int64) if order is not None else None,
34             'reverse_order': order is None
35         }
36
37         # update the attributes of the node
38         Permute.update_node_stat(node, attrs)
39         return __class__.enabled