我想找一个要学习的caffe python数据层示例。我知道Fast-RCNN有一个python数据层,但由于我不熟悉对象检测,所以它相当复杂。
所以我的问题是,是否有一个python数据层示例,我可以学习如何定义自己的数据准备过程?
例如,如何定义python数据层比caffe "ImageDataLayer"
做更多的数据增加(例如翻译,旋转等)。
非常感谢你
您可以使用"Python"
图层:在python中实现的图层,以将数据提供给您的网络。 (参见添加type: "Python"
层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
的更多信息,请参阅this thread。
您可以使用预取here找到数据加载层的草图。
@ Shai的答案很棒。同时,我在一个caffe-master的PR中找到了另一个关于python数据层的详细例子。 https://github.com/BVLC/caffe/pull/3471/files我希望这个详细的例子对其他人有帮助。