Managing HDF5 Object Reference

六月ゝ 毕业季﹏ 提交于 2019-12-24 04:33:06

问题


I am trying to load a mat file for the Street View House Numbers (SVHN) Dataset http://ufldl.stanford.edu/housenumbers/ in Python with the following code

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


回答1:


To get an idea of the data layout you could execute

h5dump ./sv/train/digitStruct.mat

but there are also other methods like visit or visititems.

A good reference that can help you and that seems to have already addressed a very similar problem (if not the same) recently is the following SO post:
h5py, access data in Datasets in SVHN
For example the snippet:

import h5py
import numpy

def get_name(index, hdf5_data):
    name = hdf5_data['/digitStruct/name']
    print ''.join([chr(v[0]) for v in hdf5_data[name[index][0]].value])

labels_file = 'train/digitStruct.mat'
f = h5py.File(labels_file)
for j in range(33402):
    get_name(j, f)

will print the name of the files. I get for example:

7459.png
7460.png
7461.png
7462.png
7463.png
7464.png
7465.png

You can generalize from here.



来源:https://stackoverflow.com/questions/41578516/managing-hdf5-object-reference

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!