在caffe 中增加一个什么都不做的layer(不考虑forward&backward算法,只考虑打通流程)
英文教程 https://github.com/BVLC/caffe/wiki/Development#developing-new-layers
一 修改 /src/caffe/proto/caffe.proto
1 在 LayerParameter 增加
optional MyLayerParameter my_layer_param = 147; (这个ID :147。是因为最近的layerid是146 增加新的layer的话,id数字递增就好了)
2 添加 自己的 MyLayerParameter
message MyLayerParameter {
// add MyLayerParameter
optional float pam = 1 [default = 1.0];// 增加一个变量,调研一下怎么获取。
enum Engine {
DEFAULT = 0;
CAFFE = 1;
CUDNN = 2;
}
optional Engine engine = 2 [default = DEFAULT];
}
二 在include/layers/ 增加 MyLayer .hpp文件。样例
#ifndef CAFFE_MY_LAYER_HPP_
#define CAFFE_MY_LAYER_HPP_
#include <vector>
#include "caffe/blob.hpp"
#include "caffe/layer.hpp"
#include "caffe/proto/caffe.pb.h"
namespace caffe {
template <typename Dtype>
class MyLayer : public Layer<Dtype> {
public:
explicit MyLayer(const LayerParameter& param)
: Layer<Dtype>(param) {}
//virtual void Reshape(const vector<Blob<Dtype>*>& bottom,
// const vector<Blob<Dtype>*>& top);
virtual inline const char* type() const { return "My"; }
virtual inline int ExactNumBottomBlobs() const { return 1; }
virtual inline int MinTopBlobs() const { return 1; }
virtual void Reshape(const<