shuffle_channels.hpp
1 //*****************************************************************************
2 // Copyright 2017-2021 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 Op
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
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 validate_and_infer_types() override;
57 
58  virtual std::shared_ptr<Node>
59  clone_with_new_inputs(const OutputVector& new_args) const override;
60 
61  int64_t get_axis() const { return m_axis; }
62  int64_t get_group() const { return m_group; }
63  bool evaluate(const HostTensorVector& outputs,
64  const HostTensorVector& inputs) const override;
65 
66  private:
67  /// \brief Generates a shape required to permute the data
68  ///
69  /// \param data_shape - Shape of the original input data tensor
70  /// \return A 4D tensor to be used to reshape the input data before shuffling it
71  Shape get_pre_shuffle_shape(const Shape& data_shape) const;
72  bool evaluate_shuffle_channels(const HostTensorVector& outputs,
73  const HostTensorVector& inputs) const;
74 
75  int64_t m_axis;
76  int64_t m_group;
77  };
78  }
79  using v0::ShuffleChannels;
80  }
81 }
82 
83 NGRAPH_SUPPRESS_DEPRECATED_END
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:71
A handle for one of a node's outputs.
Definition: node_output.hpp:42
Shape for a tensor.
Definition: shape.hpp:31
Root of all actual ops.
Definition: op.hpp:29
Permutes data in the channel dimension of the input.
Definition: shuffle_channels.hpp:34
bool evaluate(const HostTensorVector &outputs, const HostTensorVector &inputs) const override
Evaluates the op on input_values putting results in output_values.
const NodeTypeInfo & get_type_info() const override
Definition: shuffle_channels.hpp:37
virtual void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
ShuffleChannels(const Output< Node > &data, const int64_t axis=1, const int64_t group=1)
Constructs a ShuffleChannels node.
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
Definition: type.hpp:39