def _write_batch_lmdb(db, batch, image_count):
 try:
  with db.begin(write=True) as lmdb_txn:
   for (i, datum) in enumerate(batch):
    key = ('%08d_%d' % ((image_count + i), datum.label))
    lmdb_txn.put(key, datum.SerializeToString())
 except lmdb.MapFullError:
  curr_limit = db.info()['map_size']
  new_limit = (curr_limit * 2)
  try:
   db.set_mapsize(new_limit)
  except AttributeError as e:
   version = tuple((int(x) for x in lmdb.__version__.split('.')))
   if (version < (0, 87)):
    raise Error(('py-lmdb is out of date (%s vs 0.87)' % lmdb.__version__))
   else:
    raise e
  _write_batch_lmdb(db, batch, image_count)

def _write_batch_lmdb ( db , batch , image_count ) : try : with db . begin ( write = True ) as lmdb_txn : for ( i , datum ) in enumerate ( batch ) : key = ( '%08d_%d' % ( ( image_count + i ) , datum . label ) ) lmdb_txn . put ( key , datum . SerializeToString ( ) ) except lmdb . MapFullError : curr_limit = db . info ( ) [ 'map_size' ] new_limit = ( curr_limit * 2 ) try : db . set_mapsize ( new_limit ) except AttributeError as e : version = tuple ( ( int ( x ) for x in lmdb . __version__ . split ( '.' ) ) ) if ( version < ( 0 , 87 ) ) : raise Error ( ( 'py-lmdb is out of date (%s vs 0.87)' % lmdb . __version__ ) ) else : raise e _write_batch_lmdb ( db , batch , image_count )
write a batch to an lmdb database .