Caffe2 - C++ API
A deep learning, cross platform ML framework
channel_shuffle_op.h
1 #ifndef CAFFE2_OPERATORS_CHANNEL_SHUFFLE_OP_H_
2 #define CAFFE2_OPERATORS_CHANNEL_SHUFFLE_OP_H_
3 
4 #include "caffe2/core/context.h"
5 #include "caffe2/core/logging.h"
6 #include "caffe2/core/operator.h"
7 
8 namespace caffe2 {
9 
10 template <typename T, class Context>
11 class ChannelShuffleOp final : public Operator<Context> {
12  public:
13  USE_OPERATOR_CONTEXT_FUNCTIONS;
14 
15  template <class... Args>
16  explicit ChannelShuffleOp(Args&&... args)
17  : Operator<Context>(std::forward<Args>(args)...),
18  order_(StringToStorageOrder(
19  this->template GetSingleArgument<std::string>("order", "NCHW"))),
20  OP_SINGLE_ARG(int, "group", group_, 1) {
21  CAFFE_ENFORCE_NE(order_, StorageOrder::UNKNOWN);
22  }
23 
24  bool RunOnDevice() override {
25  return order_ == StorageOrder::NCHW ? RunOnDeviceWithOrderNCHW()
26  : RunOnDeviceWithOrderNHWC();
27  }
28 
29  bool RunOnDeviceWithOrderNCHW();
30 
31  bool RunOnDeviceWithOrderNHWC();
32 
33  private:
34  const StorageOrder order_;
35  const int group_;
36 };
37 
38 template <typename T, class Context>
39 class ChannelShuffleGradientOp final : public Operator<Context> {
40  public:
41  USE_OPERATOR_CONTEXT_FUNCTIONS;
42 
43  template <class... Args>
44  explicit ChannelShuffleGradientOp(Args&&... args)
45  : Operator<Context>(std::forward<Args>(args)...),
46  order_(StringToStorageOrder(
47  this->template GetSingleArgument<std::string>("order", "NCHW"))),
48  OP_SINGLE_ARG(int, "group", group_, 1) {
49  CAFFE_ENFORCE_NE(order_, StorageOrder::UNKNOWN);
50  }
51 
52  bool RunOnDevice() override {
53  return order_ == StorageOrder::NCHW ? RunOnDeviceWithOrderNCHW()
54  : RunOnDeviceWithOrderNHWC();
55  }
56 
57  bool RunOnDeviceWithOrderNCHW();
58 
59  bool RunOnDeviceWithOrderNHWC();
60 
61  private:
62  const StorageOrder order_;
63  const int group_;
64 };
65 
66 } // namespace caffe2
67 
68 #endif // CAFFE2_OPERATORS_CHANNEL_SHUFFLE_OP_H_
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13