我有一个 lmdb 数据库,我正在尝试读取它的内容。具有讽刺意味的是,屏幕上没有任何内容。这是我为从 lmdb 读取而编写的代码片段:
import caffe
import lmdb
import numpy as np
from caffe.proto import caffe_pb2
import cv2
import sys
db_train = lmdb.open('mnist_train_lmdb')
db_train_txn = db_train.begin()
cursor = db_train_txn.cursor()
print db_train
print db_train_txn
print db_train_txn.cursor()
datum = caffe_pb2.Datum()
index = sys.argv[0]
size_train = 50000
size_test = 10000
data_train = np.zeros((size_train, 1, 28, 28))
label_train = np.zeros(size_train, dtype=int)
print 'Reading training data...'
i = -1
for key, value in cursor:
i = i + 1
if i % 1000 == 0:
print i
if i == size_train:
break
datum.ParseFromString(value)
label = datum.label
data = caffe.io.datum_to_array(datum)
data_train[i] = data
label_train[i] = label
这打印:
<Environment object at 0x0000000009CE3990>
<Transaction object at 0x0000000009CE1810>
<Cursor object at 0x0000000009863738>
Reading training data...
Reading test data...
似乎 for 循环根本没有运行。我在这里想念什么?
我检查了一下,这似乎是从 lmdb 读取的正常方式,我见过的所有源示例都有类似的方法。