1, installation Lmdb
2. Ubuntu system command: Pip install Lmdb
3. Running code: combine_lmdb.py
#!/usr/bin/env Python2
#-*-Coding:utf-8-*-
"""
Created on Sun 12 17:50:48 2018
@author: Sarah
"""
Import Lmdb
ENV1 = Lmdb.open ("/home/www/www_python/dataset/train_001_lmdb")
Env2 = Lmdb.open ("/home/www/www_python/dataset/train_002_lmdb")
TXN1 = Env1.begin ()
TXN2 = Env2.begin ()
Database1 = Txn1.cursor ()
Database2 = Txn2.cursor ()
Env3 = Lmdb.open ("/home/www/www_python/dataset/train_result_lmdb", Map_size=int (1e12))
Txn3 = Env3.begin (write=true)
Print (Env3.stat ())
Count =0
For (key, value) in Database1:
# put the data into the result database transaction
Txn3.put (key, value)
Count + = 1
if (count% 1000 = = 0):
# Write data to database, required, otherwise the data will not be written to the database
Txn3.commit ()
Count = 0
Txn3 = Env3.begin (write=true)
if (count% 1000! = 0):
Txn3.commit ()
Count = 0
Txn3 = Env3.begin (write=true)
For (key, value) in Database2:
Txn3.put (key, value)
if (count% 1000 = = 0):
Txn3.commit ()
Count = 0
txn3= Env3.begin (write=true)
if (count% 1000! = 0):
Txn3.commit ()
Count = 0
Txn_3 = Env3.begin (write=true)
#查询合并前后的lmdb的数据 to confirm that the merge was successful
Print Txn1.stat () [' Entries ']
Print Txn2.stat () [' Entries ']
Print Txn3.stat () [' Entries ']
Print ("Success")
Merge of two lmdb in Caffe [Python]