def open_single_lmdb_for_write(self, lmdb_path, max_lmdb_size=1024**4, create=True, label_map=None):
'''
Opens a single LMDB for inserting ndarrays (i.e. images)
Args:
lmdb_path (str): Where to save the LMDB
max_lmdb_size (int): The maximum size in bytes of the LMDB (default: 1TB)
create (bool): If this flag is set, a potentially previously created LMDB at lmdb_path
is deleted and overwritten by this new LMDB
label_map (dictionary): If you supply a dictionary mapping string labels to integer indices, you can later
call put_single with string labels instead of int labels
'''
# delete existing LMDB if necessary
if os.path.exists(lmdb_path) and create:
self.logger.debug('Erasing previously created LMDB at %s', lmdb_path)
shutil.rmtree(lmdb_path)
self.logger.info('Opening single LMDB at %s for writing', lmdb_path)
self.database_images = lmdb.open(path=lmdb_path, map_size=max_lmdb_size)
self.txn_images = self.database_images.begin(write=True)
self.label_map = label_map
评论列表
文章目录