1 #include "caffe2/operators/sigmoid_op.h" 3 #include "caffe2/utils/eigen_utils.h" 9 bool SigmoidFunctor<CPUContext>::
10 operator()(
const int N,
const T* X,
T* Y, CPUContext* )
const {
11 EigenVectorArrayMap<T>(Y, N) =
12 T(1) / (
T(1) + (-ConstEigenVectorArrayMap<T>(X, N)).exp());
16 REGISTER_CPU_OPERATOR(
21 SigmoidFunctor<CPUContext>>);
24 OPERATOR_SCHEMA(Sigmoid)
27 .AllowInplace({{0, 0}})
28 .IdenticalTypeAndShape()
30 Apply the Sigmoid function element-wise to the input tensor. This is often used 31 as a non-linear activation function in a neural network. The sigmoid function is 34 $$Sigmoid(x) = \frac{1}{1+\exp(-x)}$$ 38 - https://github.com/pytorch/pytorch/blob/master/caffe2/operators/sigmoid_op.cc 43 <summary> <b>Example</b> </summary> 49 workspace.ResetWorkspace() 51 op = core.CreateOperator( 57 workspace.FeedBlob("X", np.random.randn(5).astype(np.float32)) 58 print("input:", workspace.FetchBlob("X")) 59 workspace.RunOperatorOnce(op) 60 print("sigmoid:", workspace.FetchBlob("Y")) 68 input: [ 1.5744036 0.31632107 1.7842269 1.4450722 -2.1726978 ] 69 sigmoid: [0.8284105 0.57842743 0.85621804 0.80923885 0.10222916] 77 .Input(0, "X",
"*(type: Tensor`<float>`)* Input tensor.")
78 .Output(0,
"Y",
"*(type: Tensor`<float>`)* Output tensor.")
81 OPERATOR_SCHEMA(SigmoidGradient)
84 .AllowInplace({{1, 0}})
86 SigmoidGradient takes both Y and dY and uses this to update dX according to the 87 chain rule and derivatives of the sigmoid function.
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...