Publishing R3
[platform/upstream/dldt.git] / model-optimizer / mo / front / mxnet / extractors / convolution.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
17 import numpy as np
18
19 from mo.front.common.extractors.utils import layout_attrs
20 from mo.front.common.partial_infer.convolution import mxnet_conv2d_infer
21
22
23 def convolution_ext(attr):
24     kernel = attr.tuple("kernel", int, None)
25     stride = attr.tuple("stride", int, (1, 1))
26     padding = attr.tuple("pad", int, (0, 0))
27     dilate = attr.tuple("dilate", int, (1, 1))
28     group = attr.int("num_group", 1)
29     output = attr.int("num_filter", None)
30
31     node_attrs = {
32         'op': 'Conv2D',
33         'bias_addable': True,
34         'bias_term': False,
35         'pad': np.array([[0, 0], [0, 0], [padding[0], padding[0]], [padding[1], padding[1]]], dtype=np.int64),
36         'pad_spatial_shape': np.array([[padding[0], padding[0]], [padding[1], padding[1]]], dtype=np.int64),
37         'dilation': np.array([1, 1, dilate[0], dilate[1]], dtype=np.int64),
38         'output_spatial_shape': None,
39         'output_shape': None,
40         'kernel_spatial': np.array([kernel[0], kernel[1]], dtype=np.int64),
41         'stride': np.array([1, 1, stride[0], stride[1]], dtype=np.int64),
42         'type': 'Convolution',
43         'group': group,
44         'output': output,
45         'layout': 'NCHW',
46         'infer': mxnet_conv2d_infer
47     }
48     node_attrs.update(layout_attrs())
49     return node_attrs