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