caffe-custom network input/image_data_layer/hdf5_data_layer
来源:互联网 发布:群晖网络存储 编辑:程序博客网 时间:2024/06/13 05:59
当需要输入定制自己的数据时候,e.g. multi-label, bbox. etc.
option 1.
修改 image_data_layer.cpp 文件
batch类有data_ label_ 两个成员变量, 把图片之外的数据输入到label_中, 然后使用slice_layer就行了
e.g. test.jpg 1 2 3 4 5
修改lines_的结构
vector<std::pair<std::string, std::vector<int>> > lines_;
定制label_的的shape
vector<int> label_shape ; label_shape.push_back(batch_size); label_shape.push_back(5); label_shape.push_back(1); label_shape.push_back(1);
然后在读取文件的时候, 以此把1 2 3 4 5 放到 label_中即可
while(getline(infile, line)){ vector<int> posx = {0}; for (int pos=0; pos< line.length(); pos+=1) { pos = line.find(' ', pos); if (pos ==-1) break; posx.push_back(pos); } posx.push_back(line.length()); vector<int> labels; for(int i=1; i<posx.size()-1; i++){ string tmp = line.substr(posx[i]+1, posx[i+1]); //cout<< tmp <<"-----------------"<<endl; labels.push_back(stoi(tmp)); } lines_.push_back(std::make_pair(line.substr(posx[0], posx[1]), labels)); }//while
int offsetlabel = batch->label_.offset(item_id); for(int i=0;i<5;i++) { *(prefetch_label + i + offsetlabel) = lines_[lines_id_].second[i]; }
最后在train的.prototxt中, 按照自己label中数据的排放方式使用slice_layer
layer {name: "split"bottom: "label"top: "label1"top: "bbox"type: "Slice"slice_param{axis: 1slice_point: 1}}
option-2
hdf5_data_layer
f = h5py.File('train0.h5', 'w')f.create_dataset('data', (10, 2,3,3), dtype='f8')f.create_dataset('label0', (10, 3), dtype='f4')f.create_dataset('label1', (10, 5), dtype='f4')for i in xrange(10): a = np.random.randn(2,3,3) l = np.random.randn(3) ll = np.random.randn(5) f['data'][i] = a f['label0'][i] = l f['label1'][i] = llf.close()with open('train.h5list', 'w') as f: f.write('train0.h5' + '\n') f.write('train1.h5' + '\n')name: "traintest"force_backward: truelayer {name: "hd5"top: "data"top: "label0"top: "label1"type: "HDF5Data"hdf5_data_param {#source: "D:\\workspace\\python\\trainh5list.txt"source: "D:\\workspace\\python\\train.h5list"batch_size: 15shuffle: true}}
---------reference---------------------
http://www.meltycriss.com/2016/07/04/caffe_1_layer/
http://stackoverflow.com/questions/33140000/how-to-feed-caffe-multi-label-data-in-hdf5-format
0 0
- caffe-custom network input/image_data_layer/hdf5_data_layer
- 梳理caffe代码image_data_layer、data_layer、window_data_layer(七)
- 关于caffe里面image_data_layer的使用
- caffe-custom new layer
- J2ME Custom Text Input
- Defining a Custom Input Source
- caffe训练siamese network
- caffe-siamese network
- caffe network 可视化
- Custom Input Views的基本用法
- Siamese Network Training with Caffe
- Transmitting Network Data Using Volley -Implementing a Custom Request
- Caffe 学习: tmux, vim, Anaconda, Caffe, Siamese network
- caffe中的siamese network(一)
- caffe中的siamese network(二)
- network of caffe and deep learning
- iOS: best tutorial of splitview + popover + custom input view
- How to add custom validator to paper-input?
- Hadoop之——Hadoop2.5.2 HA高可靠性集群搭建(Hadoop+Zookeeper)
- BSOJ:3362 聪明的农民 贪心
- 感知机
- Android 消息处理机制原理
- Java中File的常用操作及方法
- caffe-custom network input/image_data_layer/hdf5_data_layer
- Ajax访问远程WebService 配置文件、编码工作注意
- Linux_VMware虚拟机下为什么不能识别USB设备
- SQL中select使用
- 自动生成fbi代码网站
- 深入研究java.lang.Class
- C++ 虚析构函数
- 【安卓-优化点】安卓App开发思路 一步一个脚印(四)Fragment的重复利用
- 3Sum Closest(java实现)