【发布时间】:2019-02-04 05:41:02
【问题描述】:
我正在尝试创建一个包含两个数据集“数据”和“标签”的 HDF5 文件。但是,当我尝试访问上述文件时,出现如下错误:
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.4\helpers\pydev\pydevd.py", line 1664, in <module>
main()
File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.4\helpers\pydev\pydevd.py", line 1658, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.4\helpers\pydev\pydevd.py", line 1068, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.4\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/pycharm/Input_Pipeline.py", line 140, in <module>
data_h5 = f['data'][:]
File "h5py\_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
File "h5py\_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
File "C:\Users\u20x47\PycharmProjects\PCL\venv\lib\site-packages\h5py\_hl\group.py", line 177, in __getitem__
oid = h5o.open(self.id, self._e(name), lapl=self._lapl)
File "h5py\_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
File "h5py\_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
File "h5py\h5o.pyx", line 190, in h5py.h5o.open
ValueError: Not a location (invalid object ID)
用于创建数据集的代码:
h5_file.create_dataset('data', data=data_x, compression='gzip', compression_opts=4, dtype='float32')
h5_file.create_dataset('label', data=label, compression='gzip', compression_opts=1, dtype='uint8')
data_x an array of arrays. Each element in data_x is a 3D array of 1024 elements.
label is an array of arrays as well. Each element is a 1D array of 1 element.
访问上述文件的代码:
f = h5_file
data_h5 = f['data'][:]
label_h5 = f['label'][:]
print (data_h5, label_h5)
我该如何解决这个问题?这是语法错误还是逻辑错误?
【问题讨论】:
标签: python-3.x dataset hdf5