caffe 数据层示例一步一步 [英] caffe data layer example step by step
问题描述
想找一个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 I
am 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 数据层示例一步一步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!