shuffle_channels.hpp
1 // Copyright (C) 2018-2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 #pragma once
6 
7 #include <memory>
8 
9 #include "ngraph/node.hpp"
10 #include "ngraph/op/util/fused_op.hpp"
11 
12 namespace ngraph
13 {
14  namespace op
15  {
16  namespace v0
17  {
18  /// \brief Permutes data in the channel dimension of the input
19  class NGRAPH_API ShuffleChannels : public Op
20  {
21  public:
22  NGRAPH_RTTI_DECLARATION;
23 
24  ShuffleChannels() = default;
25  /// \brief Constructs a ShuffleChannels node.
26  ///
27  /// \param data - Node producing the input tensor
28  /// \param axis - channel dimension index in the data tensor. A negative value means
29  /// that the index should be calculated from the back of the input
30  /// data
31  /// shape.
32  /// \param group - number of group the channel dimension specified by axis should
33  /// be
34  /// split into
36  const int64_t axis = 1,
37  const int64_t group = 1);
38 
39  bool visit_attributes(AttributeVisitor& visitor) override;
40  size_t get_zero_based_axis() const;
41 
42  virtual void validate_and_infer_types() override;
43 
44  virtual std::shared_ptr<Node>
45  clone_with_new_inputs(const OutputVector& new_args) const override;
46 
47  int64_t get_axis() const { return m_axis; }
48  int64_t get_group() const { return m_group; }
49  bool evaluate(const HostTensorVector& outputs,
50  const HostTensorVector& inputs) const override;
51  bool has_evaluate() const override;
52 
53  private:
54  /// \brief Generates a shape required to permute the data
55  ///
56  /// \param data_shape - Shape of the original input data tensor
57  /// \return A 4D tensor to be used to reshape the input data before shuffling it
58  Shape get_pre_shuffle_shape(const Shape& data_shape) const;
59  bool evaluate_shuffle_channels(const HostTensorVector& outputs,
60  const HostTensorVector& inputs) const;
61 
62  int64_t m_axis;
63  int64_t m_group;
64  };
65  } // namespace v0
66  using v0::ShuffleChannels;
67  } // namespace op
68 } // namespace ngraph
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:59
A handle for one of a node's outputs.
Definition: node_output.hpp:33
Shape for a tensor.
Definition: shape.hpp:19
Root of all actual ops.
Definition: op.hpp:17
Permutes data in the channel dimension of the input.
Definition: shuffle_channels.hpp:20
bool evaluate(const HostTensorVector &outputs, const HostTensorVector &inputs) const override
Evaluates the op on input_values putting results in output_values.
virtual void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
bool has_evaluate() const override
Allows to get information about availability of evaluate method for the current operation.
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:16