我正在尝试使用以下代码段将一堆图像插入LMDB格式:
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())
但是,由于未压缩的字节写在磁盘上,结果文件太大了!!因此,我想知道如何在python中将编码属性设置为JPG。我已经知道C ++ api中提供了这个选项。
提前致谢