shuffle_channels.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 <memory>
20 
21 #include "ngraph/node.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 Permutes data in the channel dimension of the input
33  class NGRAPH_API ShuffleChannels : public ngraph::op::util::FusedOp
34  {
35  public:
36  static constexpr NodeTypeInfo type_info{"ShuffleChannels", 0};
37  const NodeTypeInfo& get_type_info() const override { return type_info; }
38  ShuffleChannels() = default;
39  /// \brief Constructs a ShuffleChannels node.
40  ///
41  /// \param data - Node producing the input tensor
42  /// \param axis - channel dimension index in the data tensor. A negative value means
43  /// that the index should be calculated from the back of the input
44  /// data
45  /// shape.
46  /// \param group - number of group the channel dimension specified by axis should
47  /// be
48  /// split into
49  ShuffleChannels(const Output<Node>& data,
50  const int64_t axis = 1,
51  const int64_t group = 1);
52 
53  bool visit_attributes(AttributeVisitor& visitor) override;
54  size_t get_zero_based_axis() const;
55 
56  virtual void pre_validate_and_infer_types() override;
57 
58  virtual OutputVector decompose_op() const override;
59 
60  virtual std::shared_ptr<Node>
61  clone_with_new_inputs(const OutputVector& new_args) const override;
62 
63  int64_t get_axis() const { return m_axis; }
64  int64_t get_group() const { return m_group; }
65  private:
66  /// \brief Generates a shape required to permute the data
67  ///
68  /// \param data_shape - Shape of the original input data tensor
69  /// \return A 4D tensor to be used to reshape the input data before shuffling it
70  Shape get_pre_shuffle_shape(const Shape& data_shape) const;
71 
72  int64_t m_axis;
73  int64_t m_group;
74  };
75  }
76  using v0::ShuffleChannels;
77  }
78 }
79 
80 NGRAPH_SUPPRESS_DEPRECATED_END
ngraph
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
ngraph::op::v0::ShuffleChannels::ShuffleChannels
ShuffleChannels(const Output< Node > &data, const int64_t axis=1, const int64_t group=1)
Constructs a ShuffleChannels node.
ngraph::op::v0::ShuffleChannels
Permutes data in the channel dimension of the input.
Definition: shuffle_channels.hpp:34
ngraph::AttributeVisitor
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:70