2 Copyright (c) 2018-2019 Intel Corporation
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
8 http://www.apache.org/licenses/LICENSE-2.0
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.
18 from mo.front.common.partial_infer.utils import convert_tf_padding_to_str, int64_array
19 from mo.front.extractor import FrontExtractorOp
20 from mo.front.tf.extractors.utils import tf_data_format_spatial, tf_data_format_channel, tf_data_format_batch, \
22 from mo.ops.deconvolution import Deconvolution
23 from mo.ops.op import PermuteAttrs
26 class Conv2DBackpropInputFrontExtractor(FrontExtractorOp):
27 op = 'Conv2DBackpropInput'
32 attrs = tf_create_attrs(node, 3, 2)
33 attrs.update({'op': __class__.op,
34 'get_weights_permute': PermuteAttrs.Permutation(perm=int64_array([3, 2, 0, 1]),
35 inv=int64_array([2, 3, 1, 0]))
38 # update the attributes of the node
39 Deconvolution.update_node_stat(node, attrs)
40 return __class__.enabled
43 class Conv3DBackpropInputV2InputFrontExtractor(FrontExtractorOp):
44 op = 'Conv3DBackpropInputV2'
49 attrs = tf_create_attrs(node, 4, 3)
50 attrs.update({'op': __class__.op,
51 'get_weights_permute': PermuteAttrs.Permutation(perm=int64_array([4, 3, 0, 1, 2]),
52 inv=int64_array([2, 3, 4, 1, 0]))
55 # update the attributes of the node
56 Deconvolution.update_node_stat(node, attrs)
57 return __class__.enabled
60 def tf_create_attrs(node, input_feature_channel, output_feature_channel):
61 data_format = node.pb.attr["data_format"]
64 'auto_pad': convert_tf_padding_to_str(node.pb.attr['padding']),
67 'spatial_dims': tf_data_format_spatial(data_format),
68 'channel_dims': tf_data_format_channel(data_format),
69 'batch_dims': tf_data_format_batch(data_format),
70 'pad': None, # will be inferred when input shape is known
71 'pad_spatial_shape': None,
72 'output_spatial_shape': None,
75 'stride': tf_int_list(node.pb.attr["strides"].list),
76 'type': None, # don't set type until we are sure it is really translated to correct IR; see infer function
78 'layout': data_format.s.decode(),
79 'input_feature_channel': input_feature_channel,
80 'output_feature_channel': output_feature_channel,