Merge of two lmdb in Caffe [Python]

Source: Internet
Author: User

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]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.