Caffe2 - C++ API
A deep learning, cross platform ML framework
sigmoid_op.cc
1 #include <caffe2/ideep/ideep_utils.h>
2 
3 namespace caffe2 {
4 
5 class IDEEPSigmoidOp final : public IDEEPOperator {
6  public:
7  USE_IDEEP_DEF_ALIASES();
8  USE_IDEEP_OPERATOR_FUNCTIONS();
9 
10  IDEEPSigmoidOp(const OperatorDef& operator_def, Workspace* ws)
11  : IDEEPOperator(operator_def, ws) {
12  }
13  ~IDEEPSigmoidOp() override {}
14 
15  bool RunOnDevice() override {
16  const auto& X = Input(INPUT);
17  auto* Y = Output(OUTPUT);
18 
19  ideep::eltwise_forward::compute(
20  X, *Y, ialgo::eltwise_logistic, iprop::forward_training);
21 
22  return true;
23  }
24 
25  private:
26 
27  INPUT_TAGS(INPUT);
28  OUTPUT_TAGS(OUTPUT);
29 };
30 
31 class IDEEPSigmoidGradientOp final : public IDEEPOperator {
32  public:
33  USE_IDEEP_DEF_ALIASES();
34  USE_IDEEP_OPERATOR_FUNCTIONS();
35 
36  IDEEPSigmoidGradientOp(const OperatorDef& operator_def, Workspace* ws)
37  : IDEEPOperator(operator_def, ws) {
38  }
39  ~IDEEPSigmoidGradientOp() override {}
40 
41  bool RunOnDevice() override {
42  const auto& Y = Input(OUTPUT);
43  const auto& dY = Input(OUTPUT_GRAD);
44  auto* dX = Output(INPUT_GRAD);
45 
46  ideep::eltwise_backward::compute(Y, dY, *dX, ialgo::eltwise_logistic);
47 
48  return true;
49  }
50 
51  private:
52 
53  INPUT_TAGS(OUTPUT, OUTPUT_GRAD);
54  OUTPUT_TAGS(INPUT_GRAD);
55 };
56 
57 REGISTER_IDEEP_OPERATOR(Sigmoid, IDEEPSigmoidOp);
58 REGISTER_IDEEP_OPERATOR(SigmoidGradient, IDEEPSigmoidGradientOp);
59 
60 } // namespace caffe2
sigmoid(x) = (tanh(x/2) + 1)/2 Quantized sigmoid is computed as tanh under the hood, we just use different input/output quantization parameters.
Definition: sigmoid.h:13
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 ...
Definition: blob.h:13