管理HDF5对象参考 [英] Managing HDF5 Object Reference
问题描述
我正在尝试为街景门牌号码(SVHN)数据集加载Mat文件 http://带有以下代码的python中的ufldl.stanford.edu/housenumbers/
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)
我得到[<HDF5 object reference>]
,但我需要知道实际的字符串
I get [<HDF5 object reference>]
but I need to know the actual string
推荐答案
要了解数据布局,可以执行
To get an idea of the data layout you could execute
h5dump ./sv/train/digitStruct.mat
,但是还有其他方法,例如visit
或visititems
.
but there are also other methods like visit
or visititems
.
以下SO帖子是一个很好的参考,可以帮助您,并且最近似乎已经解决了一个非常相似的问题(如果不相同):
h5py,在SVHN中访问数据集中的数据
例如,代码段:
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
7459.png
7460.png
7461.png
7462.png
7463.png
7464.png
7465.png
您可以从这里进行概括.
You can generalize from here.
这篇关于管理HDF5对象参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!