Caffe:从Python读取LMDB [英] Caffe: Reading LMDB from Python

查看:201
本文介绍了Caffe:从Python读取LMDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用caffe提取了特征,caffe会生成一个.mdb文件. 然后,我尝试使用Python读取它并将其显示为可读数字.

I've extracted features using caffe, which generates a .mdb file. Then I'm trying to read it using Python and display it as a readable number.

import lmdb

lmdb_env = lmdb.open('caffefeat')
lmdb_txn = lmdb_env.begin()
lmdb_cursor = lmdb_txn.cursor()

for key, value in lmdb_cursor:
    print str(value)

这会打印出很长的不可读的折断字符.

This prints out a very long line of unreadable, broken characters.

然后我尝试打印int(value),它返回以下内容:

Then I tried printing int(value), which returns the following:

ValueError: invalid literal for int() with base 10: '\x08\x80 \x10\x01\x18\x015\x8d\x80\xad?5'

float(value)给出以下内容:

float(value) gives the following:

ValueError: could not convert string to float:? 5????5

这是lmdb文件本身的问题,还是与数据类型的转换有关?

Is this a problem with the lmdb file itself, or does it have to do with conversion of data type?

推荐答案

这是我想出的工作代码

import caffe
import lmdb

lmdb_env = lmdb.open('directory_containing_mdb')
lmdb_txn = lmdb_env.begin()
lmdb_cursor = lmdb_txn.cursor()
datum = caffe.proto.caffe_pb2.Datum()

for key, value in lmdb_cursor:
    datum.ParseFromString(value)
    label = datum.label
    data = caffe.io.datum_to_array(datum)
    for l, d in zip(label, data):
            print l, d

这篇关于Caffe:从Python读取LMDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆