#ifndef CAFFE_CLIP_LAYER_HPP_ #define CAFFE_CLIP_LAYER_HPP_ #include #include "caffe/blob.hpp" #include "caffe/layer.hpp" #include "caffe/proto/caffe.pb.h" #include "caffe/layers/neuron_layer.hpp" namespace caffe { /** * @brief Clip: @f$ y = \max(min, \min(max, x)) @f$. */ template class ClipLayer : public NeuronLayer { public: /** * @param param provides ClipParameter clip_param, * with ClipLayer options: * - min * - max */ explicit ClipLayer(const LayerParameter& param) : NeuronLayer(param) {} virtual inline const char* type() const { return "Clip"; } protected: /** * @param bottom input Blob vector (length 1) * -# @f$ (N \times C \times H \times W) @f$ * the inputs @f$ x @f$ * @param top output Blob vector (length 1) * -# @f$ (N \times C \times H \times W) @f$ * the computed outputs @f$ * y = \max(min, \min(max, x)) * @f$ */ virtual void Forward_cpu(const vector*>& bottom, const vector*>& top); virtual void Forward_gpu(const vector*>& bottom, const vector*>& top); /** * @brief Computes the error gradient w.r.t. the clipped inputs. * * @param top output Blob vector (length 1), providing the error gradient with * respect to the outputs * -# @f$ (N \times C \times H \times W) @f$ * containing error gradients @f$ \frac{\partial E}{\partial y} @f$ * with respect to computed outputs @f$ y @f$ * @param propagate_down see Layer::Backward. * @param bottom input Blob vector (length 1) * -# @f$ (N \times C \times H \times W) @f$ * the inputs @f$ x @f$; Backward fills their diff with * gradients @f$ * \frac{\partial E}{\partial x} = \left\{ * \begin{array}{lr} * 0 & \mathrm{if} \; x < min \vee x > max \\ * \frac{\partial E}{\partial y} & \mathrm{if} \; x \ge min \wedge x \le max * \end{array} \right. * @f$ */ virtual void Backward_cpu(const vector*>& top, const vector& propagate_down, const vector*>& bottom); virtual void Backward_gpu(const vector*>& top, const vector& propagate_down, const vector*>& bottom); }; } // namespace caffe #endif // CAFFE_CLIP_LAYER_HPP_