码迷,mamicode.com
首页 > 数据库 > 详细

caffe中两个lmdb的合并 [python]

时间:2018-08-12 21:36:11      阅读:871      评论:0      收藏:0      [点我收藏+]

标签:+=   val   合并   python2   数据   auth   key   coding   trie   

1、安装lmdb

2、Ubuntu 系统命令:pip install lmdb

3、运行代码:combine_lmdb.py

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Sun Aug 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:
    # 将数据放到结果数据库事务中
    txn3.put(key, value)
    count += 1
    if(count % 1000 == 0):
        # 将数据写入数据库,必须的,否则数据不会写入到数据库中
        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的数据,确认合并成功
print txn1.stat()[‘entries‘]
print txn2.stat()[‘entries‘]
print txn3.stat()[‘entries‘]
print("success")

 

caffe中两个lmdb的合并 [python]

标签:+=   val   合并   python2   数据   auth   key   coding   trie   

原文地址:https://www.cnblogs.com/NealRiver/p/9464332.html

(0)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!