Publishing 2019 R1 content
[platform/upstream/dldt.git] / model-optimizer / mo / front / caffe / extractors / slice.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 from mo.front.caffe.collect_attributes import merge_attrs
17 from mo.front.common.partial_infer.slice import caffe_slice_infer
18
19
20 def slice_ext(proto_layer, model_layer):
21     param = proto_layer.slice_param
22     # slice_dim is deprecated parameter and is used as alias for axis
23     # however if slice_dim is defined and axis is default, we use slice_dim
24     if param.slice_dim != 1 and param.axis == 1:
25         axis = param.slice_dim
26     else:
27         axis = param.axis
28     update_attrs = {
29         'axis': axis,
30         'slice_point': param.slice_point,
31     }
32     mapping_rule = merge_attrs(param, update_attrs)
33     if 'slice_point' not in mapping_rule:
34         mapping_rule['slice_point'] = []
35     mapping_rule.update({
36         'type': 'Slice',
37         'infer': caffe_slice_infer
38     })
39     return mapping_rule