forked from torralba-lab/im2recipe-Pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_propose.py
36 lines (30 loc) · 1.04 KB
/
data_propose.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: utf-8 -*-
import time
from tqdm import *
import numpy as np
def readdata_fromlmdb():
import lmdb
import binascii
from functools import partial
import pickle
pickle.load = partial(pickle.load, encoding="latin1")
pickle.Unpickler = partial(pickle.Unpickler, encoding="latin1")
env_db = lmdb.open("./data/test_lmdb")
txn = env_db.begin()
# print (txn.get(str(200)))
# "'00003a70b1', '00047059be', '00059477e2', '0007a28fe7', '000bba053c', '000d5e4996', '00100336d5', '001243534a', '0012733d1d'"
i = 0
for key, value in txn.cursor(): # 遍历
if i < 10:
print(i, key, value)
i += 1
with open('./test_keys.pkl', 'rb') as f:
ids = pickle.load(f, encoding='iso-8859-1')
print(ids[0:10])
serialized_sample = txn.get(ids[10].encode())
print("fuck", serialized_sample)
sample = pickle.loads(serialized_sample, encoding="bytes")
print(sample)
imgs = sample['imgs'.encode()]
print(imgs)
env_db.close()