caffe数据层示例一步一步

caffe data layer example step by step

想找一个caffepython数据层的例子来学习。 我知道 Fast-RCNN 有一个 python 数据层,但它相当复杂,因为我 我不熟悉对象检测。
所以我的问题是,是否有 python 数据层示例,我可以在其中学习如何定义自己的数据准备程序?
例如,如何定义一个 python 数据层做更多的数据扩充 (比如平移、旋转等)比caffe"ImageDataLayer".

非常感谢

您可以使用 "Python" 层:在 python 中实现的层将数据馈送到您的网络中。 (参见添加 type: "Python" 的示例)。

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 的更多信息,请参阅
您可以使用 pre-fetch here.

找到数据加载层的草图

@Shai 的回答很好。同时,我在caffe-master的一个PR中找到了另一个关于python数据层的详细例子。 https://github.com/BVLC/caffe/pull/3471/files 我希望这个详细的示例对其他人有所帮助。