caffe添加新层windows
2017-02-04 17:12
375 查看
参考博客:
http://46aae4d1e2371e4aa769798941cef698.devproxy.yunshipei.com/kkk584520/article/details/52721838
因为是在windows-caffe下,所以在上述博客基础上做了些较为详细的记录,外加一点点修改
一、修改caffe.proto
在路径 caffe-windows-master\src\caffe\proto中找到caffe.proto.prototxt,添加
还有
添加完成后保存,然后就是windows-caffe下的多一步的操作,需要点击extract_proto批处理文件,重新生成caffe.pb.hpp和caffe.pb.cc文件。如果没有extract_proto文件,直接重新编译caffe工程即可。
二、添加新层头文件
在路径caffe-windows-master\include\caffe\layers下添加all_pass_layer.hpp文件
这里我在上述博客的基础上,在CPU模式下编译。
三、添加新层源文件
caffe-windows-master\src\caffe\layers路径下添加all_pass_layer.cpp
在路径下添加之后,需要在caffe VS C++工程中添加all_pass_layer.hpp文件和all_pass_layer.cpp文件
四、重新编译
选中caffe工程,点击rebuild即可
五、实验添加的新层
写个简单的测试网络结构 deploy.prototxt
name: “AllPassTest”
layer {
name: “data”
type: “Input”
top: “data”
input_param { shape: { dim: 10 dim: 3 dim: 227 dim: 227 } }
}
layer {
name: “ap”
type: “AllPass”
bottom: “data”
top: “conv1”
all_pass_param {
key: 12.88
}
}
windows-caffe测试方法和在Linux下相同,打开CMD,进入caffe根目录,deploy.prototxt文件和caffe.exe放在同一个目录下。
http://46aae4d1e2371e4aa769798941cef698.devproxy.yunshipei.com/kkk584520/article/details/52721838
因为是在windows-caffe下,所以在上述博客基础上做了些较为详细的记录,外加一点点修改
一、修改caffe.proto
在路径 caffe-windows-master\src\caffe\proto中找到caffe.proto.prototxt,添加
optional AllPassParameter all_pass_param = 155;
还有
message AllPassParameter { optional float key = 1 [default = 0]; }
添加完成后保存,然后就是windows-caffe下的多一步的操作,需要点击extract_proto批处理文件,重新生成caffe.pb.hpp和caffe.pb.cc文件。如果没有extract_proto文件,直接重新编译caffe工程即可。
二、添加新层头文件
在路径caffe-windows-master\include\caffe\layers下添加all_pass_layer.hpp文件
#ifndef CAFFE_ALL_PASS_LAYER_HPP_ #define CAFFE_ALL_PASS_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 { template <typename Dtype> class AllPassLayer : public NeuronLayer<Dtype> { public: explicit AllPassLayer(const LayerParameter& param) : NeuronLayer<Dtype>(param) {} virtual inline const char* type() const { return "AllPass"; } protected: 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); 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_ALL_PASS_LAYER_HPP_
这里我在上述博客的基础上,在CPU模式下编译。
三、添加新层源文件
caffe-windows-master\src\caffe\layers路径下添加all_pass_layer.cpp
#include <algorithm> #include <vector> #include "caffe/layers/all_pass_layer.hpp" #include <iostream> using namespace std; #define DEBUG_AP(str) cout<<str<<endl namespace caffe { template <typename Dtype> void AllPassLayer<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] = bottom_data[i]; } DEBUG_AP("Here is All Pass Layer, forwarding."); DEBUG_AP(this->layer_param_.all_pass_param().key()); } template <typename Dtype> void AllPassLayer<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]; } } DEBUG_AP("Here is All Pass Layer, backwarding."); DEBUG_AP(this->layer_param_.all_pass_param().key()); } #ifdef CPU_ONLY STUB_GPU(AllPassLayer); #endif INSTANTIATE_CLASS(AllPassLayer); REGISTER_LAYER_CLASS(AllPass); } // namespace caffe
在路径下添加之后,需要在caffe VS C++工程中添加all_pass_layer.hpp文件和all_pass_layer.cpp文件
四、重新编译
选中caffe工程,点击rebuild即可
五、实验添加的新层
写个简单的测试网络结构 deploy.prototxt
name: “AllPassTest”
layer {
name: “data”
type: “Input”
top: “data”
input_param { shape: { dim: 10 dim: 3 dim: 227 dim: 227 } }
}
layer {
name: “ap”
type: “AllPass”
bottom: “data”
top: “conv1”
all_pass_param {
key: 12.88
}
}
windows-caffe测试方法和在Linux下相同,打开CMD,进入caffe根目录,deploy.prototxt文件和caffe.exe放在同一个目录下。
Debug\caffe.exe time -model deploy.prototxt
相关文章推荐
- 【caffe-Windows】新层添加——LSTM
- 【caffe-Windows】添加工程-以classification为例
- windows-caffe添加新层
- 【caffe-Windows】添加工程-以classification为例(2017-04-11)
- caffe添加新层windows
- caffe-windows添加自己的loss层
- caffe添加新层windows
- caffe-windows添加自己的工程
- windows caffe 添加UpsampleLayer BNLayer以支持SegNet网络结构
- Caffe-Windows添加新层
- 在添加windows应用程序时出现“automation服务器不能创建对象 ”的错误
- 为Windows 2000添加五笔型码输入法
- Windows外壳扩展编程之添加右键菜单
- 利用工作流给Windows SharePoint Service 3.0添加Skype通知功能
- 给自己的Blog程序添加对Windows Live Writer的支持
- Windows中为添加/删除程序提速
- Windows外壳扩展编程之添加右键菜单
- 如何在MSN Space 中添加Windows Media Player 播放模块
- debian学习笔记--添加windows字体
- 如何使用PHP往windows中添加用户