Caffe源码:relu_layer.cpp
来源:互联网 发布:淘宝买家修改评价链接 编辑:程序博客网 时间:2024/06/03 09:26
@brief ReluLayer层反向传播
Relu激活函数:
反向传导时,
#include <algorithm>#include <vector>#include "caffe/layers/relu_layer.hpp"namespace caffe {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(); 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));//proto中设置为0 }}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();//拿到ReluLayer的输入值 const Dtype* top_diff = top[0]->cpu_diff();//拿到ReluLayer输入梯度 Dtype* bottom_diff = bottom[0]->mutable_cpu_diff();//要从ReluLayer反向传播的梯度 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)//如果输入激活值>0 要反向传播的梯度=该层传进的梯度值*输入的值 + negative_slope * (bottom_data[i] <= 0));//如果输入激活值<=0 梯度为0 } }}#ifdef CPU_ONLYSTUB_GPU(ReLULayer);#endifINSTANTIATE_CLASS(ReLULayer);} // namespace caffe
阅读全文
0 0
- Caffe源码:relu_layer.cpp
- Caffe Relu_layer.cpp 学习
- 学习笔记: 源码 relu_layer.cpp 略见
- Caffe源码解读:relu_layer前向传播和反向传播
- Caffe源码解析caffe.cpp
- caffe源码:math_functions.cpp
- Caffe源码:Softmax_loss_layer.cpp
- Caffe源码:inner_product_layer.cpp
- Caffe源码:pooling_layer.cpp
- caffe下relu_layer.cu详解
- caffe源码分析:softmax_layer.cpp && softmax_loss_layer.cpp
- caffe源码分析--data_layer.cpp
- caffe源码分析--softmax_layer.cpp
- caffe源码分析--poolinger_layer.cpp
- caffe源码之blob.cpp
- Caffe源码:io.cpp 分析
- 【Caffe】002 caffe.cpp源码解析
- caffe源码学习中-tools/caffe.cpp
- mybatis批量更新 allowMultiQueries
- IDC:2017年Q3全球可穿戴设备总出货量2630万台 小米Fitbit并列第一
- 微信官方提供的生成二维码接口得到的是当前公众号的二维码。
- Uiautomator小记之 Uidevice
- 在此行找到多个注释:
- Caffe源码:relu_layer.cpp
- 安装虚拟机出现的一些问题,总是会让人不知所措。下面总结了几点
- Eclipse(maven)
- 案例分析|链家网大数据平台枢纽——工具链
- 基于VBS实现SecureCRT的命令自动输入和自动记录
- 静态代理模式
- SMS短信服务平台接口开发
- PHP+SQL Server 连接数据库(二)
- 小心被套路!想拿钱的你认真看看