Caffe2 - C++ API
A deep learning, cross platform ML framework
conv_transpose_op.h
1 #ifndef CAFFE2_OPERATORS_CONV_TRANSPOSE_OP_H_
2 #define CAFFE2_OPERATORS_CONV_TRANSPOSE_OP_H_
3 
4 #include "caffe2/core/context.h"
5 #include "caffe2/core/operator.h"
6 #include "caffe2/operators/conv_transpose_unpool_op_base.h"
7 
8 namespace caffe2 {
9 
10 template <typename T, class Context>
11 class ConvTransposeOp final : public ConvTransposeUnpoolBase<Context> {
12  public:
13  USE_CONV_TRANSPOSE_UNPOOL_BASE_FUNCTIONS(Context);
14  template <class... Args>
15  explicit ConvTransposeOp(Args&&... args)
16  : ConvTransposeUnpoolBase<Context>(std::forward<Args>(args)...) {}
17 
18  bool RunOnDeviceWithOrderNCHW() override;
19  bool RunOnDeviceWithOrderNHWC() override;
20 
21  private:
22  Tensor col_buffer_;
23  Tensor bias_multiplier_;
24  // Input: X, W, b
25  // Output: Y
26  INPUT_TAGS(INPUT, FILTER, BIAS);
27 };
28 
29 template <typename T, class Context>
30 class ConvTransposeGradientOp final : public ConvTransposeUnpoolBase<Context> {
31  public:
32  USE_CONV_TRANSPOSE_UNPOOL_BASE_FUNCTIONS(Context);
33  template <class... Args>
34  explicit ConvTransposeGradientOp(Args&&... args)
35  : ConvTransposeUnpoolBase<Context>(std::forward<Args>(args)...),
36  no_bias_(this->template GetSingleArgument<bool>("no_bias", false)) {
37  CAFFE_ENFORCE(
38  !(no_bias_ && OutputSize() == 3),
39  "If bias is not present, you should not have 3 grad output.");
40  }
41 
42  bool RunOnDeviceWithOrderNCHW() override;
43  bool RunOnDeviceWithOrderNHWC() override;
44 
45  private:
46  Tensor col_buffer_;
47  Tensor bias_multiplier_;
48  const bool no_bias_;
49  // input: X, W, dY
50  // output: dW, optionally db and dX
51  INPUT_TAGS(INPUT, FILTER, OUTPUT_GRAD);
52  OUTPUT_TAGS(FILTER_GRAD, BIAS_OR_INPUT_GRAD, INPUT_GRAD);
53 };
54 
55 } // namespace caffe2
56 
57 #endif // CAFFE2_OPERATORS_CONV_TRANSPOSE_OP_H_
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13