2 Copyright (c) 2018 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.
22 def tf_expand_dims_infer(node):
23 input_node = node.in_nodes()[0]
24 output_node = node.out_node()
25 if input_node.shape is None:
28 # TensorFlow style with dynamic input
29 if len(node.in_nodes()) > 1:
30 axis_node = node.in_nodes()[1]
31 if isinstance(axis_node.value, np.ndarray) and axis_node.value.size > 1:
32 log.error("ExpandDims operation : axis should be scalar")
34 expand_axis = axis_node.value.item()
35 node.graph.remove_edge(axis_node.id, node.id)
37 if not node.has_valid('expand_axis'):
38 log.error("ExpandDims axis is not defined")
40 expand_axis = node.expand_axis
42 if expand_axis is None:
45 output_node.shape = np.insert(input_node.shape, expand_axis, [1])
46 # convert data type of the shape to int64 explicitly
47 output_node.shape = output_node.shape.astype(np.int64)
48 if input_node.value is not None:
49 output_node.value = np.array(np.reshape(input_node.value, output_node.shape))
53 node['dim'] = output_node.shape