SSD: ReLU6
1、在src\caffe\proto\caffe.proto中搜索message LayerParameter,在optional ReLUParameter relu_param = 123之后添加optional ReLU6Parameter relu6_param = 208; (最后的分号别忘了)
2、搜索message ReLUParameter,在这个ReLUParameter实现结构之后添加
// Message that stores parameters used by ReLU6Layer
message ReLU6Parameter {
enum Engine {
DEFAULT = 0;
CAFFE = 1;
CUDNN = 2;
}
optional Engine engine = 2 [default = DEFAULT];
}
支持proto头文件修改完毕,接下来添加所需的头文件和实现文件。
1.在blob/ssd/include/caffe/layers文件夹下新建relu6_layer.hpp,将
- #ifndef CAFFE_RELU_LAYER_HPP_
- #define CAFFE_RELU_LAYER_HPP_
- #include <vector>
- #include "caffe/blob.hpp"
- #include "caffe/layer.hpp"
- #include "caffe/proto/caffe.pb.h"
- #include "caffe/layers/neuron_layer.hpp"
- namespace caffe {
- /**
- * @brief Rectified Linear Unit non-linearity @f$ y = \min(6, \max(0, x)) @f$.
- * The simple max is fast to compute, and the function does not saturate.
- */
- template <typename Dtype>
- class ReLU6Layer : public NeuronLayer<Dtype> {
- public:
- /**
- * @param param provides ReLUParameter relu_param,
- * with ReLULayer options:
- * - negative_slope (\b optional, default 0).
- * the value @f$ \nu @f$ by which negative values are multiplied.
- */
- explicit ReLU6Layer(const LayerParameter& param)
- : NeuronLayer<Dtype>(param) {}
- virtual inline const char* type() const { return "ReLU6"; }
- 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(0, x)
- * @f$ by default. If a non-zero negative_slope @f$ \nu @f$ is provided,
- * the computed outputs are @f$ y = \max(0, x) + \nu \min(0, x) @f$.
- */
- virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
- const vector<Blob<Dtype>*>& top);
- virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,
- const vector<Blob<Dtype>*>& top);
- /**
- * @brief Computes the error gradient w.r.t. the ReLU 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 \le 0 \\
- * \frac{\partial E}{\partial y} & \mathrm{if} \; x > 0
- * \end{array} \right.
- * @f$ if propagate_down[0], by default.
- * If a non-zero negative_slope @f$ \nu @f$ is provided,
- * the computed gradients are @f$
- * \frac{\partial E}{\partial x} = \left\{
- * \begin{array}{lr}
- * \nu \frac{\partial E}{\partial y} & \mathrm{if} \; x \le 0 \\
- * \frac{\partial E}{\partial y} & \mathrm{if} \; x > 0
- * \end{array} \right.
- * @f$.
- */
- virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,
- const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);
- virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,
- const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);
- };
- } // namespace caffe
- #endif // CAFFE_RELU_LAYER_HPP_
2.在blob/ssd/src/caffe/layers文件夹下新建relu6_layer.cpp,将
- #include <algorithm>
- #include <vector>
- #include "caffe/layers/relu6_layer.hpp"
- namespace caffe {
- template <typename Dtype>
- void ReLU6Layer<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] = std::min(std::max(bottom_data[i], Dtype(0)), Dtype(6));
- }
- }
- template <typename Dtype>
- void ReLU6Layer<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();
- for (int i = 0; i < count; ++i) {
- bottom_diff[i] = top_diff[i] *
- ((bottom_data[i] > 0 && bottom_data[i] < 6));
- }
- }
- }
- #ifdef CPU_ONLY
- STUB_GPU(ReLU6Layer);
- #endif
- INSTANTIATE_CLASS(ReLU6Layer);
- REGISTER_LAYER_CLASS(ReLU6);
- } // namespace caffe
3.在blob/ssd/src/caffe/layers文件夹下新建relu6_layer.cu,将
- #include <algorithm>
- #include <vector>
- #include "caffe/layers/relu6_layer.hpp"
- namespace caffe {
- template <typename Dtype>
- __global__ void ReLU6Forward(const int n, const Dtype* in, Dtype* out) {
- CUDA_KERNEL_LOOP(index, n) {
- out[index] = in[index] < 0 ? 0: (in[index] > 6 ? 6 : in[index]);
- }
- }
- template <typename Dtype>
- void ReLU6Layer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,
- const vector<Blob<Dtype>*>& top) {
- const Dtype* bottom_data = bottom[0]->gpu_data();
- Dtype* top_data = top[0]->mutable_gpu_data();
- const int count = bottom[0]->count();
- // NOLINT_NEXT_LINE(whitespace/operators)
- ReLU6Forward<Dtype><<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(
- count, bottom_data, top_data);
- CUDA_POST_KERNEL_CHECK;
- // << " count: " << count << " bottom_data: "
- // << (unsigned long)bottom_data
- // << " top_data: " << (unsigned long)top_data
- // << " blocks: " << CAFFE_GET_BLOCKS(count)
- // << " threads: " << CAFFE_CUDA_NUM_THREADS;
- }
- template <typename Dtype>
- __global__ void ReLU6Backward(const int n, const Dtype* in_diff,
- const Dtype* in_data, Dtype* out_diff) {
- CUDA_KERNEL_LOOP(index, n) {
- out_diff[index] = in_diff[index] * ((in_data[index] > 0)
- && (in_data[index] < 6));
- }
- }
- template <typename Dtype>
- void ReLU6Layer<Dtype>::Backward_gpu(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]->gpu_data();
- const Dtype* top_diff = top[0]->gpu_diff();
- Dtype* bottom_diff = bottom[0]->mutable_gpu_diff();
- const int count = bottom[0]->count();
- // NOLINT_NEXT_LINE(whitespace/operators)
- ReLU6Backward<Dtype><<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>(
- count, top_diff, bottom_data, bottom_diff);
- CUDA_POST_KERNEL_CHECK;
- }
- }
- INSTANTIATE_LAYER_GPU_FUNCS(ReLU6Layer);
- } // namespace caffe
重新编译ssd。
SSD: ReLU6的更多相关文章
- 移动端目标识别(3)——使用TensorFlow Lite将tensorflow模型部署到移动端(ssd)之Running on mobile with TensorFlow Lite (写的很乱,回头更新一个简洁的版本)
承接移动端目标识别(2) 使用TensorFlow Lite在移动设备上运行 在本节中,我们将向您展示如何使用TensorFlow Lite获得更小的模型,并允许您利用针对移动设备优化 ...
- SSD框架训练自己的数据集
SSD demo中详细介绍了如何在VOC数据集上使用SSD进行物体检测的训练和验证.本文介绍如何使用SSD实现对自己数据集的训练和验证过程,内容包括: 1 数据集的标注2 数据集的转换3 使用SSD如 ...
- 光驱SSD安装Win7+ubuntu系统双系统
准备条件: U盘,32GB,三星品牌 SSD,120GB,三星品牌 win7旗舰版,Ghost系统(安装简单嘛),Ylmf_Ghost_Win7_SP1_x64_2016_1011.iso ubunt ...
- 创建Azure DS 虚拟机并附加SSD硬盘
$subscriptionName = "Windows Azure Enterprise Trial" #订阅名称 $location = "China East&qu ...
- 关闭电脑SSD的磁盘碎片整理
小白往往会把机械硬盘时代的习惯带进固态硬盘时代,比如碎片整理.机械硬盘时代砖家最喜欢告诉小白:“系统慢了吧?赶紧碎片整理撒.”小白屁颠屁颠地整理去了.殊不知碎片整理对于SSD来说完全就是种折磨.这种“ ...
- SQL Server 2014新特性探秘(2)-SSD Buffer Pool Extension
简介 SQL Server 2014中另一个非常好的功能是,可以将SSD虚拟成内存的一部分,来供SQL Server数据页缓冲区使用.通过使用SSD来扩展Buffer-Pool,可以使得大量随 ...
- Macbook SSD硬盘空间不够用了?来个Xcode大瘦身吧!
原文转自:http://www.jianshu.com/p/03fed9a5fc63 日期:2016-04-22 最近突然发现我的128G SSD硬盘只剩下可怜的8G多,剩下这么少的一点空间连X ...
- 搭把手教美工妹妹如何通过升级SSD提升电脑性能
-----by LinHan 不单单适用于妹子,我这名的意思的妹子也能看懂. 以下教程依据实践和部分互联网资料总结得出,向博客园, CSDN的前辈们致谢:同时,如有说的不正确或有不到位的地方,麻烦指出 ...
- [archlinux][hardware] ThankPad T450自带SSD做bcache之后的使用寿命分析
这个分析的起因,是由于我之前干了这两个事: [troubleshoot][archlinux][bcache] 修改linux文件系统 / 分区方案 / 做混合硬盘 / 系统转生大!手!术!(调整底层 ...
随机推荐
- npm的安装和使用?
参考: http://www.cnblogs.com/chyingp/p/npm.html 在css中使用变量, 采用less或sass来编译css 改变网页网站开发和构建的方式, 除了用emmet( ...
- cannot open window service on computer '.' in window application
1.配置错误,需要检查对应的windows service的exe文件所在文件夹下的log 2.在命令行通过Start-Service启动,需要有管理员权限.
- Print a file's last modified date in Bash
date -r <filename> #!/usr/bin/env bash for i in /var/log/*.out; do stat -f "%Sm" -t ...
- P3301 [SDOI2013]方程
思路 容斥的挺好的练习题 对于第二个条件,可以直接使m减去suma2,使得第二个条件舍去,然后m再减去n,使得问题转化成有n1个变量要满足小于等于某个数的条件,其他的随便取,求整数解的个数 对n1,以 ...
- 【ASP.Net】publish asp.net to local IIS
做web项目难免要将项目部署, 要么部署在azure上,要么部署在本地, 使用IIS去host. 部署步骤很简单, 1. vs打开你的web项目, 项目名上面右键选择publish 2. 在弹出的pu ...
- Kubernetes简介
Kubernetes is an open-source platform designed to automate deploying, scaling, and operating applica ...
- spring-tool-suite使用教程,并创建spring配置文件
本文为博主原创,未经允许不得转载: 在应用springMVC框架的时候,每次创建spring的xml配置文件时,需要很多步骤,非常麻烦. 所以spring提供了spring-tool-suite插件, ...
- HDU 3401 Trade(斜率优化dp)
http://acm.hdu.edu.cn/showproblem.php?pid=3401 题意:有一个股市,现在有T天让你炒股,在第i天,买进股票的价格为APi,卖出股票的价格为BPi,同时最多买 ...
- 中国地区免费注册bitcointalk论坛教程
bitcointalk论坛是著名的老牌比特币论坛,中本聪当年也在这里和各路大神探讨.但现在国家的高墙禁止网民访问. 你可能会用一个国外的代理工具来看贴,看贴确实可以,但是如果想注册,注册完后就会发现帐 ...
- 《spring boot 实战》读书笔记
前言:虽然已经用spring boot开发过一套系统,但是之前都是拿来主义,没有系统的,全面的了解过这套框架.现在通过学习<spring boot实战>这本书,希望温故知新.顺便实现自己的 ...