I define a function to load image data from lmdb file and subtract mean value, but this function gets slow from 0.1s to 1.0s after thousands of loop.
def load_image(lmdb_file, keys, im_size, pixel_means):
img_str = ''
env = lmdb.open(lmdb_file, readonly=True)
with env.begin() as txn:
for key in keys:
img_str += txn.get(key)
env.close()
img_data = np.fromstring(img_str, dtype=np.uint8).astype(np.float32)
img = np.reshape(img_data, [len(keys), im_size[0], im_size[1], 3])
img -= pixel_means
return img
It is quite annoying when loading data from disk. Is there a way to speed up?