def get_sample(self, i):
"""Return the ith sample from `data_db`.
Parameter
---------
i : int
"""
if 0 > i or self.nb_samples <= i:
raise IndexError('The selected sample number is out of range: %d'
% i)
# Convert the sample number to a string with trailing zeros
key = encode_str('{:010}'.format(i))
with self._lmdb_env.begin(db=self.data_db) as txn:
# Read msgpack from LMDB and decode each value in it
obj = msgpack.unpackb(txn.get(key))
for k in obj:
# Keys are stored as byte objects (hence the `decode_str`)
obj[decode_str(k)] = msgpack.unpackb(
obj.pop(k), object_hook=decode_data)
return obj
评论列表
文章目录