Getting Data into LMDB for Caffe

This borders on blogspam, but I found it so useful that I can't help but share.

Evan Shelhamer shared here the format that Caffe expects its input data to be.

import caffe
import lmdb

in_db ='image-lmdb', map_size=int(1e12))
with in_db.begin(write=True) as in_txn:
    for in_idx, in_ in enumerate(inputs):
        im =
        im_dat =, 0, 1)))
        in_txn.put('{:0>10d}'.format(in_idx), im_dat.SerializeToString())

Comments are closed.