使用lmdb对ImageNet数据进行快速读取(Pytorch)

reference

  1. https://github.com/npuichigo/pytorch_lmdb_dataset
  2. https://pytorch.org/docs/stable/_modules/torchvision/datasets/folder.html#ImageFolder
  3. https://github.com/Lyken17/Efficient-PyTorch
  4. https://github.com/xunge/pytorch_lmdb_imagenet

选择lmdb的原因
The default combination datasets.ImageFolder + data.DataLoader is not enough for large scale classification. According to my experience, even I upgrade to Samsung 960 Pro (read 3.5 GB/s, write 2.0 GB/s), whole training pipeline still suffers at disk I/O.

The reason causing is the slow reading of discountiuous small chunks. To optimize, we need to dump small JPEG images into a large binary file. TensorFlow has its own TFRecord and MXNet uses recordIO. Beside these two, there are other options like hdf5, pth, n5, lmdb etc. Here I choose lmdb because

TFRecord is a private protocal which is hard to hack into. RecordIO’s documentation is confusing and do not provide a clean python API.
hdf5 pth n5, though with a straightforward json-like API, require to put the whole file into memory. This is not practicle when you play with large dataset like imagenet.

转换流程

  1. 下载代码
    git clone https://github.com/xunge/pytorch_lmdb_imagenet
  2. 修改folder2lmdb.py里的train和val路径,然后运行代码
    python folder2lmdb.py
    
  3. 修改dataloader,开始训练。在机械硬盘上,相比于pytorch自带的数据读取接口,使用lmdb的data I/O速度提高了大概十倍左右。
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值