0
$\begingroup$

I am trying to work with the Street View House Numbers Dataset in Python. To load the .mat file digitStruct.mat in python I am using H5py

import h5py
labels_file = './sv/train/digitStruct.mat'
f = h5py.File(labels_file)
struct= f.values()
names = struct[1].values()
print(names[1][1].value)

I get [<HDF5 object reference>] but I need to know the actual string

$\endgroup$
1

2 Answers 2

1
$\begingroup$

If you already have a <HDF5 object reference>, and you want to know the real data, here is one approach:

import h5py
labels_file = './sv/train/digitStruct.mat'
f = h5py.File(labels_file)
ref = f.get('/digitStruct/name').value[0][0]  # <HDF5 object reference>
print(f[ref].value)

In my environment, f[ref].value shows:

In [84]: f[ref].value
Out[84]: 
array([[ 49],
       [ 46],
       [112],
       [110],
       [103]], dtype=uint16)

For more information on object references, you can refer to http://docs.h5py.org/en/latest/refs.html

$\endgroup$
1
  • $\begingroup$ What do those numbers represent? I got a similar result, but was expecting to see strings rather than an array of numbers. How does one decode the string values? $\endgroup$ Sep 14, 2019 at 22:32
0
$\begingroup$

I have not checked the dataset but this is what I suggest. Have a look at this method - get to extract.

Apart from this, I also suggest checking Matlab engine for python.

eng = matlab.engine.start_matlab()
data = eng.load(labels_file,nargout=1)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.