foolyc

create LMDB in python(multi-channel data)

the LMDB creating tool /caffe/build/tools/convert_imageset can’t handle datasets with channel greater than 4, when creating LMDB file from multi-channel, we can use lmdb module in python.

import caffe
import numpy as np
import lmdb
mydb = lmdb.open('/path/to/your/lmdb', map_size=int(1e12))
db_txn = mydb.begin(write=True)
index = 0
im_data = np.zeros([6, 227, 227])
label = 0
in_dat = caffe.io.array_to_datum(im_data, label)
in_datss = in_dat.SerializeToString()
db_txn.put('{:0>10d}'.format(index), in_datss)
index = index + 1
db_txn.commit()
mydb.close()

本文由foolyc创作和发表,采用BY-NC-SA国际许可协议进行许可
转载请注明作者及出处,本文作者为foolyc
本文标题为create LMDB in python(multi-channel data)
本文链接为http://foolyc.com//2016/11/15/pycaffe-blog/.