问题描述
我想找到一个caffe python数据层示例来学习.我知道Fast-RCNN有一个python数据层,但是自从我对对象检测不熟悉.
所以我的问题是,是否有一个python数据层示例,在这里我可以学习如何定义自己的数据准备过程?
例如,如何定义python数据层会做更多的数据扩充(例如平移,旋转等)而不是caffe "ImageDataLayer"
.
I want to find a caffe python data layer example to learn.I know that Fast-RCNN has a python data layer, but it's rather complicated since Iam not familiar with object detection.
So my question is, is there a python data layer example where I can learn how to define my own data preparation procedure?
For example, how to do define a python data layer do much more data augmentation(such as translation, rotation etc.) than caffe "ImageDataLayer"
.
非常感谢您
推荐答案
您可以使用"Python"
层:用python实现的层,用于将数据馈入网络. (请参见在此处添加一个type: "Python"
图层的示例.)
You can use a "Python"
layer: a layer implemented in python to feed data into your net. (See an example for adding a type: "Python"
layer here).
import sys, os
sys.path.insert(0, os.environ['CAFFE_ROOT']+'/python')
import caffe
class myInputLayer(caffe.Layer):
def setup(self,bottom,top):
# read parameters from `self.param_str`
...
def reshape(self,bottom,top):
# no "bottom"s for input layer
if len(bottom)>0:
raise Exception('cannot have bottoms for input layer')
# make sure you have the right number of "top"s
if len(top)!= ...
raise ...
top[0].reshape( ... ) # reshape the outputs to the proper sizes
def forward(self,bottom,top):
# do your magic here... feed **one** batch to `top`
top[0].data[...] = one_batch_of_data
def backward(self, top, propagate_down, bottom):
# no back-prop for input layers
pass
有关param_str
的更多信息,请参见此线程.
您可以在此处此处预取找到数据加载层的草图.
For more information on param_str
see this thread.
You can find a sketch of a data loading layer with pre-fetch here.
这篇关于caffe数据层示例逐步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!