elu_layer.hpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #ifndef CAFFE_ELU_LAYER_HPP_
  2. #define CAFFE_ELU_LAYER_HPP_
  3. #include <vector>
  4. #include "caffe/blob.hpp"
  5. #include "caffe/layer.hpp"
  6. #include "caffe/proto/caffe.pb.h"
  7. #include "caffe/layers/neuron_layer.hpp"
  8. namespace caffe {
  9. /**
  10. * @brief Exponential Linear Unit non-linearity @f$
  11. * y = \left\{
  12. * \begin{array}{lr}
  13. * x & \mathrm{if} \; x > 0 \\
  14. * \alpha (\exp(x)-1) & \mathrm{if} \; x \le 0
  15. * \end{array} \right.
  16. * @f$.
  17. */
  18. template <typename Dtype>
  19. class ELULayer : public NeuronLayer<Dtype> {
  20. public:
  21. /**
  22. * @param param provides ELUParameter elu_param,
  23. * with ELULayer options:
  24. * - alpha (\b optional, default 1).
  25. * the value @f$ \alpha @f$ by which controls saturation for negative inputs.
  26. */
  27. explicit ELULayer(const LayerParameter& param)
  28. : NeuronLayer<Dtype>(param) {}
  29. virtual inline const char* type() const { return "ELU"; }
  30. protected:
  31. /**
  32. * @param bottom input Blob vector (length 1)
  33. * -# @f$ (N \times C \times H \times W) @f$
  34. * the inputs @f$ x @f$
  35. * @param top output Blob vector (length 1)
  36. * -# @f$ (N \times C \times H \times W) @f$
  37. * the computed outputs @f$
  38. * y = \left\{
  39. * \begin{array}{lr}
  40. * x & \mathrm{if} \; x > 0 \\
  41. * \alpha (\exp(x)-1) & \mathrm{if} \; x \le 0
  42. * \end{array} \right.
  43. * @f$.
  44. */
  45. virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
  46. const vector<Blob<Dtype>*>& top);
  47. virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,
  48. const vector<Blob<Dtype>*>& top);
  49. /**
  50. * @brief Computes the error gradient w.r.t. the ELU inputs.
  51. *
  52. * @param top output Blob vector (length 1), providing the error gradient with
  53. * respect to the outputs
  54. * -# @f$ (N \times C \times H \times W) @f$
  55. * containing error gradients @f$ \frac{\partial E}{\partial y} @f$
  56. * with respect to computed outputs @f$ y @f$
  57. * @param propagate_down see Layer::Backward.
  58. * @param bottom input Blob vector (length 1)
  59. * -# @f$ (N \times C \times H \times W) @f$
  60. * the inputs @f$ x @f$; Backward fills their diff with
  61. * gradients @f$
  62. * \frac{\partial E}{\partial x} = \left\{
  63. * \begin{array}{lr}
  64. * 1 & \mathrm{if} \; x > 0 \\
  65. * y + \alpha & \mathrm{if} \; x \le 0
  66. * \end{array} \right.
  67. * @f$ if propagate_down[0].
  68. */
  69. virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,
  70. const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);
  71. virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,
  72. const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);
  73. };
  74. } // namespace caffe
  75. #endif // CAFFE_ELU_LAYER_HPP_