Insert images as encoded file to LMDB using Python

734 views Asked by At

I'm trying to insert a bunch of images into the LMDB format using the following snippet:

with env.begin(write=True) as txn:
for i in range(N):
    datum = caffe.proto.caffe_pb2.Datum()
    datum.channels = X.shape[1]
    datum.height = X.shape[2]
    datum.width = X.shape[3]
    datum.data = X[i].tobytes()  # or .tostring() if numpy < 1.9
    datum.label = int(y[i])
    str_id = '{:08}'.format(i)

# The encode is only essential in Python 3
    txn.put(str_id.encode('ascii'), datum.SerializeToString())

However, as the uncompressed bytes are written on the disk, the resultant file is so huge!! Accordingly, I'm wondering how I can set the encoding property to JPG in python. I am already aware that the very option is available in C++ api.

Thanks in advance

0

There are 0 answers