caffe icon indicating copy to clipboard operation
caffe copied to clipboard

Load leveldb data in Python

Open Kelvin-Zhong opened this issue 12 years ago • 3 comments

I have extracted the features from a image, which are store in the directory "features", and I want to use this features for further processing. However, when I use python and use leveldb to open it and see the values of these features, it show something following:

Input: leveldb.Get('1') Output: \x00\x005\x00\x00\x00\x005\x00\x00\x00\x005\xe5\xb8Q?5L\x7f\x8a? ''''''' \x00\x00\x00\x005n\xe0>@5\x00\x00\x00\x005\x00\x00\x00\x0050Tr@5\xb9\x17\xef@'

What's this meaning? And How can I retrieve the feature value that I want from this?? I use python, Thanks a lot!!!~~

Kelvin-Zhong avatar Jul 07 '14 03:07 Kelvin-Zhong

It is stored as a serialised caffe "Datum" protobuffer, you can convert it to a numpy array like this:

import caffe
from caffe.proto import caffe_pb2

datum = caffe_pb2.Datum.FromString(db.Get('1'))
arr = caffe.io.datum_to_array(datum)

jamt9000 avatar Jul 07 '14 10:07 jamt9000

Hi @shelhamer I also extracted the features which are stored in leveldb format in the folder features by the name data.mdb. When I run your python script I get the error : NameError Traceback (most recent call last) in () 4 import leveldb 5 ----> 6 datum = caffe_pb2.Datum.FromString(db.Get('1')) 7 arr = caffe.io.datum_to_array(datum) 8

NameError: name 'db' is not defined

Can you please let me know what I should do? I am new to lmdb fromat hence sorry for asking!!

anurikadisha avatar Jun 04 '15 09:06 anurikadisha

It looks like you need to define db first. db = plyvel.DB('/path/to/db/folder') before calling db.get

shethsh avatar Jun 29 '15 08:06 shethsh