depth_to_space.hpp
1 //*****************************************************************************
2 // Copyright 2017-2020 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 #pragma once
18 
19 #include "ngraph/node.hpp"
20 #include "ngraph/op/op.hpp"
21 #include "ngraph/op/util/attr_types.hpp"
22 #include "ngraph/op/util/fused_op.hpp"
23 
24 NGRAPH_SUPPRESS_DEPRECATED_START
25 
26 namespace ngraph
27 {
28  namespace op
29  {
30  namespace v0
31  {
32  /// \brief DepthToSpace permutes data from the depth dimension of the input blob into
33  /// spatial dimensions.
34  ///
35  /// \note Values from the depth dimension (assuming NCHW layout) are moved in
36  /// spatial blocks to the height and width dimensions.
37  ///
38  /// Output node produces a tensor with shape:
39  /// [N, C/(blocksize * blocksize), H * blocksize, W * blocksize]
40  class NGRAPH_API DepthToSpace : public ngraph::op::util::FusedOp
41  {
42  public:
43  static constexpr NodeTypeInfo type_info{"DepthToSpace", 0};
44  const NodeTypeInfo& get_type_info() const override { return type_info; }
45  enum class DepthToSpaceMode
46  {
47  // The input depth is divided to [block_size, ..., block_size, new_depth]
48  BLOCKS_FIRST,
49  // The input depth is divided to [new_depth, block_size, ..., block_size]
50  DEPTH_FIRST
51  };
52 
53  DepthToSpace() = default;
54  /// \brief Constructs a DepthToSpace operation.
55  ///
56  /// \param data Node producing the input tensor
57  /// \param mode Specifies how the input depth dimension is split to block
58  /// coordinates
59  /// \param block_size The size of the block of values to be moved
60  DepthToSpace(const Output<Node>& data,
61  const DepthToSpaceMode& mode,
62  std::size_t block_size = 1);
63 
64  DepthToSpace(const Output<Node>& data,
65  const std::string& mode,
66  std::size_t block_size = 1);
67  bool visit_attributes(AttributeVisitor& visitor) override;
68 
69  std::size_t get_block_size() const { return m_blocksize; }
70  DepthToSpaceMode get_mode() const { return m_mode; }
71  virtual OutputVector decompose_op() const override;
72 
73  virtual std::shared_ptr<Node>
74  clone_with_new_inputs(const OutputVector& new_args) const override;
75 
76  protected:
77  std::size_t m_blocksize;
78  DepthToSpaceMode m_mode;
79  DepthToSpaceMode mode_from_string(const std::string& mode) const;
80  };
81  }
82  using v0::DepthToSpace;
83  }
84 
85  NGRAPH_API
86  std::ostream& operator<<(std::ostream& s, const op::v0::DepthToSpace::DepthToSpaceMode& type);
87 
88  template <>
89  class NGRAPH_API AttributeAdapter<op::v0::DepthToSpace::DepthToSpaceMode>
90  : public EnumAttributeAdapterBase<op::v0::DepthToSpace::DepthToSpaceMode>
91  {
92  public:
93  AttributeAdapter(op::v0::DepthToSpace::DepthToSpaceMode& value)
94  : EnumAttributeAdapterBase<op::v0::DepthToSpace::DepthToSpaceMode>(value)
95  {
96  }
97 
98  static constexpr DiscreteTypeInfo type_info{
99  "AttributeAdapter<op::v0::DepthToSpace::DepthToSpaceMode>", 0};
100  const DiscreteTypeInfo& get_type_info() const override { return type_info; }
101  };
102 }
103 
104 NGRAPH_SUPPRESS_DEPRECATED_END
ngraph::op::v0::DepthToSpace
DepthToSpace permutes data from the depth dimension of the input blob into spatial dimensions.
Definition: depth_to_space.hpp:41
ngraph::op::v0::DepthToSpace::DepthToSpace
DepthToSpace(const Output< Node > &data, const DepthToSpaceMode &mode, std::size_t block_size=1)
Constructs a DepthToSpace operation.
ngraph::DiscreteTypeInfo
Definition: type.hpp:39
ngraph
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
ngraph::AttributeVisitor
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:70