Caffe源码(七):ReLU,Sigmoid and Tanh
来源:互联网 发布:永清环保怎么样知乎 编辑:程序博客网 时间:2024/05/17 08:02
目录
- 目录
- 简单介绍
- ReLU 激活函数
- Sigmoid 激活函数
- Tanh 激活函数
- ReLU 主要函数
- Forward_cpu 函数
- Backward_cpu 函数
- Sigmoid主要函数
- Forward_cpu 函数
- Backward_cpu 函数
- Tanh主要函数
- Forward_cpu 函数
- Backward_cpu 函数
简单介绍
ReLU 激活函数:
ReLu使得网络可以自行引入稀疏性,在没做预训练情况下,以ReLu为激活的网络性能优于其它激活函数。
数学表达式:
Sigmoid 激活函数:
sigmoid 激活函数在神经网络学习方面,可以将重点特征推向中央区,将非重点特征推向两侧区。
数学表达式:
Tanh 激活函数:
Tanh 激活函数使得输出与输入的关系能保持非线性单调上升和下降关系,比sigmoid 函数延迟了饱和期,对神经网路的容错性好。
数学表达式:
ReLU 主要函数
Forward_cpu 函数:
template <typename Dtype>void ReLULayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) { const Dtype* bottom_data = bottom[0]->cpu_data(); Dtype* top_data = top[0]->mutable_cpu_data(); const int count = bottom[0]->count(); Dtype negative_slope = this->layer_param_.relu_param().negative_slope(); //输入小于0时的斜率,默认为0; for (int i = 0; i < count; ++i) { top_data[i] = std::max(bottom_data[i], Dtype(0)) + negative_slope * std::min(bottom_data[i], Dtype(0)); }//输入大于零斜率为1,小于0斜率为negative_slope。}
Backward_cpu 函数:
template <typename Dtype>void ReLULayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top, const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) { if (propagate_down[0]) { const Dtype* bottom_data = bottom[0]->cpu_data(); const Dtype* top_diff = top[0]->cpu_diff(); Dtype* bottom_diff = bottom[0]->mutable_cpu_diff(); const int count = bottom[0]->count(); Dtype negative_slope = this->layer_param_.relu_param().negative_slope(); for (int i = 0; i < count; ++i) { bottom_diff[i] = top_diff[i] * ((bottom_data[i] > 0) + negative_slope * (bottom_data[i] <= 0)); } }}
Sigmoid主要函数
Forward_cpu 函数:
template <typename Dtype>void SigmoidLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) { const Dtype* bottom_data = bottom[0]->cpu_data(); Dtype* top_data = top[0]->mutable_cpu_data(); const int count = bottom[0]->count(); for (int i = 0; i < count; ++i) { top_data[i] = sigmoid(bottom_data[i]); }}
sigmoid 函数定义如下:
template <typename Dtype>inline Dtype sigmoid(Dtype x) { return 1. / (1. + exp(-x));}
Backward_cpu 函数:
求导:
template <typename Dtype>void SigmoidLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top, const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) { if (propagate_down[0]) { const Dtype* top_data = top[0]->cpu_data(); const Dtype* top_diff = top[0]->cpu_diff(); Dtype* bottom_diff = bottom[0]->mutable_cpu_diff(); const int count = bottom[0]->count(); for (int i = 0; i < count; ++i) { const Dtype sigmoid_x = top_data[i]; bottom_diff[i] = top_diff[i] * sigmoid_x * (1. - sigmoid_x); } }}
Tanh主要函数
Forward_cpu 函数:
template <typename Dtype>void TanHLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) { const Dtype* bottom_data = bottom[0]->cpu_data(); Dtype* top_data = top[0]->mutable_cpu_data(); const int count = bottom[0]->count(); for (int i = 0; i < count; ++i) { top_data[i] = tanh(bottom_data[i]); }}
Backward_cpu 函数:
求导:
template <typename Dtype>void TanHLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top, const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) { if (propagate_down[0]) { const Dtype* top_data = top[0]->cpu_data(); const Dtype* top_diff = top[0]->cpu_diff(); Dtype* bottom_diff = bottom[0]->mutable_cpu_diff(); const int count = bottom[0]->count(); Dtype tanhx; for (int i = 0; i < count; ++i) { tanhx = top_data[i]; bottom_diff[i] = top_diff[i] * (1 - tanhx * tanhx); } }}
0 0
- Caffe源码(七):ReLU,Sigmoid and Tanh
- ReLU Sigmoid and Tanh
- ReLU Sigmoid and Tanh(2)
- sigmoid、tanh、softplus和ReLu激活函数
- 神经网络之激活函数(sigmoid、tanh、ReLU)
- 激活函数-Sigmoid,Tanh,ReLu,softplus,softmax
- 神经网络之激活函数(sigmoid、tanh、ReLU)
- 神经网络中的激活函数(activation function)-Sigmoid, ReLu, TanHyperbolic(tanh), softmax, softplus
- 机器学习笔记-神经网络中激活函数(activation function)对比--Sigmoid、ReLu,tanh
- 常见激活函数(sigmoid/logistic/tanh/softmax/ReLU关系解释)
- 四种激活函数(Relu Linear Sigmoid Tanh)
- 深度学习——激活函数Sigmoid/Tanh/ReLU
- caffe学习系列四Sigmod、Tanh、ReLU等Layer源码分析
- 神经网络激活函数sigmoid relu tanh 为什么sigmoid 容易梯度消失
- 人工神经网络中的activation function的作用以及ReLu,tanh,sigmoid激励函数的区别
- 一次面试引发的问题:激活函数Relu,sigmoid ,tanh的角逐
- 神经网络中的激活函数-Sigmoid, ReLu, TanHyperbolic(tanh), softmax, softplus简述
- 常用的激活函数总结(Sigmoid函数、Tanh函数、ReLu函数、Softmax函数)
- Error:Execution failed for task ':app:dexDebug'. > com.android.ide.common.process.ProcessException:
- Lua中的捕获
- 华为OJ(统计大写字母个数)
- 网络编程笔记一:基础入门
- 颜色缩减(带Trackbar)【从毛星云Opencv3编程入门P75 P111例程改编】
- Caffe源码(七):ReLU,Sigmoid and Tanh
- Leetcode -- Remove Duplicates from Sorted List II
- activity 启动模式
- Java学习之路0802(网络通信)
- java初始化顺序
- 【sql server】SQL触发器
- 安装archlinux+cinnamon笔记
- 工厂方法
- 华为OJ(求最大连续bit数)