Caffe2 - C++ API
A deep learning, cross platform ML framework
dropout_op.h
1 #ifndef CAFFE2_OPERATORS_DROPOUT_OP_H_
2 #define CAFFE2_OPERATORS_DROPOUT_OP_H_
3 
4 #include "caffe2/core/context.h"
5 #include "caffe2/core/logging.h"
6 #include "caffe2/core/operator.h"
7 #include "caffe2/utils/math.h"
8 
9 namespace caffe2 {
10 
11 template <typename T, class Context>
12 class DropoutOp final : public Operator<Context> {
13  public:
14  USE_OPERATOR_CONTEXT_FUNCTIONS;
15  DropoutOp(const OperatorDef& operator_def, Workspace* ws)
16  : Operator<Context>(operator_def, ws),
17  ratio_(OperatorBase::GetSingleArgument<float>("ratio", 0.5)),
18  is_test_(
19  OperatorBase::GetSingleArgument<int>(OpSchema::Arg_IsTest, 0)) {
20  CAFFE_ENFORCE_GE(ratio_, 0);
21  CAFFE_ENFORCE_LT(ratio_, 1);
22  }
23 
24  bool RunOnDevice() override;
25 
26  protected:
27  float ratio_;
28  bool is_test_;
29  // Input: X; Output: Y, mask.
30 };
31 
32 template <typename T, class Context>
33 class DropoutGradientOp final : public Operator<Context> {
34  public:
35  USE_OPERATOR_CONTEXT_FUNCTIONS;
36  DropoutGradientOp(const OperatorDef& operator_def, Workspace* ws)
37  : Operator<Context>(operator_def, ws),
38  ratio_(OperatorBase::GetSingleArgument<float>("ratio", 0.5)),
39  is_test_(
40  OperatorBase::GetSingleArgument<int>(OpSchema::Arg_IsTest, 0)) {
41  CAFFE_ENFORCE_GE(ratio_, 0);
42  CAFFE_ENFORCE_LT(ratio_, 1);
43  }
44 
45  bool RunOnDevice() override;
46 
47  protected:
48  float ratio_;
49  bool is_test_;
50  // Input: dY, mask; Output: dX
51 };
52 
53 } // namespace caffe2
54 
55 #endif // CAFFE2_OPERATORS_DROPOUT_OP_H_
Workspace is a class that holds all the related objects created during runtime: (1) all blobs...
Definition: workspace.h:47
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...