caffe中兩個lmdb的合併 python

2022-08-18 10:51:11 字數 2061 閱讀 7028

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")

lmdb的形式,**convert_imageset.cpp

【lmdb的key】 八位數的字首+源檔名

string key_str = caffe::format_int(line_id, 8) + "_" + lines[line_id].first;

【lmdb的value】  讀取影象到datum,然後序列後為字串

status = readimagetodatum(root_folder + lines[line_id].first,

lines[line_id].second, resize_height, resize_width, is_color,

enc, &datum);

string out;

check(datum.serializetostring(&out));

txn->put(key_str, out);

待解決的問題:

1、lmdb記憶體的設定

2、caffe中多標籤的lmdb 問題

3、lmdb讀寫顯示問題

ps.小王有話說: 人生不容易,大家隨便活

合併兩個byte

byte sshead system.text.encoding.unicode.getbytes this is head byte sscontent system.text.encoding.unicode.getbytes this is content.sshead sscontent b...

合併兩個DataTable

方法1 sqlconnection myconnection new sqlconnection server localhost uid sa pwd database wjoa string sql1 select from resoursemanage t sqldataadapter ada...

pta兩個有序鍊錶的合併 21 合併兩個有序鍊錶

分別遍歷兩個鍊錶,把數放到列表中,運用sort方法。再用尾插法,遍歷列表,建立新的有序鍊錶。class solution def mergetwolists self,l1 listnode,l2 listnode listnode sum def list2num node while node ...