tags: caffe
Caffe Add a new neural layer
You can refer to the frame header file of other layers, etc., inherit the neural layer
Retreat method: virtual inline const char * type () const {return "myneuron";
If you just need a CPU method, you can comment on forward_gpu () and backward_gpu ().
Can refer to the frame header file of other layers, etc.
Rewriting method Layersetup, implementing the parameters from prototxt, if you don't need to read parameters, you can not rewrite
Rewriting the method RESHAPE, if you don't modify the inheritance class, you can use it without rewriting
Rewriting method forward_cpu; Caffe has a function of some mathematical operations. CAFFE calculation is a matrix operation
Override method backward_cpu (no must)
If you want GPU support, you need to create src / caffe / src / my_neuron_layer.cu. Similar rewriting method
Forward_gpu / backward_gpu (non-must)
message LayerParameter{
...
++optional MyNeuronParameter
mysquare_param = 150; Cannot repeat the flag number
...
}
...
++message MyNeuronParameter{
++ Optional float power = 1 {default = 2}; parameters in Layer
++
}
...
message V1LayerParameter{
...
++ MYNEURON = 40; add a parameter setting
...
}
INSTANTIATE_CLASS(MyNeuronLayer);
REGISTER_LAYER_CLASS(MyNeuron);
If there is MY_NEURON_LAYER.CU, add
INSTANTIATE_LAYER_GPU_FUNCS(MyNeuronLayer);
Re-build Caffe
Sixth step test
You can write a prototxt that only the input layer and custom layer
Then test it
The test procedure is as follows:
import numpy as np
import matplotlib.pyplot as plt
import os
import sys
import caffe
deploy_file="./deploy.prototxt"
test_data="5,jpg"
if __name__ ='__main__':
net = caffe.Net(deploy_file,caffe.TEST)
transformer = caffe.io.Transformer({'data':net.blobs['data'].data.shape})
transformer.set_transpose('data',(2,0,3))
img= caffe.io.load_image(test_data,color=False)
net.blobs['data'].data[...]=transformer.preprocess('data',img)
print net.blobs['data'].data
out = net.forward()
print out['data_out']
other:
Custom data layer
1. Create a new defined header file include / caffe / layers / my_data_Layer.hpp
Retreat method: Virtual inline const char * type () const {return "mydata";
2, rewrite Layersetup, shuffleimage, load_batch
3, proto / caffe.proto registration new Layer
//my new data parameter
optional MyDataParameter my_data_param = 50
//my new data layer for infer image data
optional MyDataPatameter my_data_param=150
...
message MyDataParameter{
}
1.RoiPoolingLayer 2.SmoothL1LossLayer Caffe's Fast_Rcnn implementation, which includes RoiPoolingLayer and SmoothL1LossLayer https://github.com/rbgirshick/caffe-fast-rcnn/ Want to add ROIPooling...
The caffe framework can perform basic deep learning operations, but you need to define layers yourself or port other defined layers in order to extend functionality. The following is an example of add...
Modify caffe \ src \ caffe \ proto \ caffe.proto Finally, add the parameter information centerloss layer Add layer type information, note number is not the same as the other layers. To add ...
0. Add a simple data layer to generate incremental square matrices or square matrices with the same elements 1. insrc/caffe/proto/caffe.protoAdd layer parameters inmessage LayerParameterDeclare a new ...
There are two ways, one is to use python layer is relatively simple, the other is to use C++. 1.python layer Referencehttp://chrischoy.github.io/research/caffe-python-layer/ The name of the module is ...
1. Installation of caffe Here mainly talk about installing caffe under anaconda: First, open the supporting python environment: Then followInstall caffe under anaconda Note if it appears cmake: /home/...
Add a Normalize layer in Caffe Computer in my computer is the official source code of Caffe, but recently when I ran SSD, I found that the official source code is actually there is no NORMALIZE layer,...
Recent want to take advantage of using python write layer, but also in the use of the process into a lot of pits, record it, in order to deepen the impression; First, under the python files under pyth...
Reprinted: According to this old man's blog, I realized it again, but this old man actually realized it on the window, and I realized it on ubntu, which was basically successful. Record it below. 1 In...
The new version of caffe is slightly different from the old version of caffe. The old version of caffe needs to be changed to /src/caffe/layer_factory.cpp, but the new version does not. canreference F...