[Caffe]: HDF5Data Layer

Tensorflow、Pytorch和Caffe2的相继问世后,Caffe的热度和优势已逐渐消失。
最近,为了跑对比的实验,用到了HDF5Data层。
遇到一些问题,写篇博客记录以下。

HDF5Data Layer

// Message that stores parameters used by HDF5DataLayer
message HDF5DataParameter {
  // Specify the data source.
  optional string source = 1;
  // Specify the batch size.
  optional uint32 batch_size = 2;

  // Specify whether to shuffle the data.
  // If shuffle == true, the ordering of the HDF5 files is shuffled,
  // and the ordering of data within any given HDF5 file is shuffled,
  // but data between different files are not interleaved; all of a file's
  // data are output (in a random order) before moving onto another file.
  optional bool shuffle = 3 [default = false];
}

HDF5Data层是Caffe提供的能够灵活控制输入数据的接口,上图是它的参数定义。如上图,HDF5Data层只有3种参数,一个指定路径的list、一个指定每个批次的训练数量和是否打乱训练数据顺序。

HDF5文件生成

使用该层需要将数据存成hdf5格式,这通过python能够很容易的实现。
推荐用h5py库,仅需三行就能将numpy存进一个hdf5文件里。

import h5py
import numpy as np

data = np.random.randn(128,1)
with h5py.File('test.h5', 'w') as fh:
    fh.create_dataset('data', data=data)

使用HDF5Data层

layer{
    name:"data"
    type:"HDF5Data"
    top:"data"
    top:"label"
    include{phase:TRAIN}
    hdf5_data_param{
    source:"train.txt"  #train.txt保存h5文件的路径,可包含多个路径,每行一个
    batch_size: 256
    shuffle: true       #是否打乱同一个文件内的数据顺序
    }
}

如图所示,HDF5Data层不支持减均值、随机剪切等数据操作,所以要在创建HDF5文件时完成。

综上,HDF5Data层还是蛮好用的。


                                                                2018.03.16 记
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值