h5py读取h5文件报错:Unable to open object (bad heap free list)

2022-09-09 18:02:29 浏览数 (1)

前言

最近在复现一篇论文的代码时发现了一个致命问题,研究了一天,终于还是破解了。网上找了半天,一个类似的解决方案都没有,记录一下。

错误出现的代码位置:

代码语言:javascript复制
self.feature_app_file = h5py.File(self.opt.input_app_feature, 'r', driver='core')

错误信息

代码语言:javascript复制
Traceback (most recent call last):
  File "train.py", line 259, in <module>
    train(opt)
  File "train.py", line 133, in train
    data = loader.get_batch('train')
  File "/data/czw/code/SMAN-main/dataloader.py", line 248, in get_batch
    tmp_fc, tmp_att, tmp_c3d_feature, tmp_token, ix, tmp_wrapped = self._prefetch_process[split].get()
  File "/data/czw/code/SMAN-main/dataloader.py", line 117, in get
    tmp = self.split_loader.next()
  File "/data/anaconda3/envs/video_czw/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 819, in __next__
    return self._process_data(data)
  File "/data/anaconda3/envs/video_czw/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 846, in _process_data
    data.reraise()
  File "/data/anaconda3/envs/video_czw/lib/python3.6/site-packages/torch/_utils.py", line 369, in reraise
    raise self.exc_type(msg)
KeyError: Caught KeyError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "/data/anaconda3/envs/video_czw/lib/python3.6/site-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop
    data = fetcher.fetch(index)
  File "/data/anaconda3/envs/video_czw/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/data/anaconda3/envs/video_czw/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/data/czw/code/SMAN-main/dataloader.py", line 231, in __getitem__
    att_feat = np.array(self.feature_box_file[(self.info['images'][ix]['id'])])
  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 "/data/anaconda3/envs/video_czw/lib/python3.6/site-packages/h5py/_hl/group.py", line 288, 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
KeyError: 'Unable to open object (bad heap free list)

反正这个bad heap free list错误是第一次见,也是第一次解决。

解决方案

其实很简单,就是把后面的 driver='core'删了,就可以了。

代码语言:javascript复制
self.feature_app_file = h5py.File(self.opt.input_app_feature, 'r')

完结,撒花~

0 人点赞