报错情况和解决方法
Error1
Traceback (most recent call last):
File "main.py", line 119, in <module>
train_loader = data.get_loader('train')
File "/home/liuyibing/vqa/bottom-up-attention-vqa/utilities/dataset.py", line 72, in get_loader
image_feature_path,
File "/home/liuyibing/vqa/bottom-up-attention-vqa/utilities/dataset.py", line 97, in __init__
self.img_id2idx = self._create_img_id_to_idx()
File "/home/liuyibing/vqa/bottom-up-attention-vqa/utilities/dataset.py", line 106, in _create_img_id_to_idx
with h5py.File(self.image_features_path, 'r') as features_file:
File "/home/share/liuyibing/Anaconda3/envs/py3_torch_v1.4/lib/python3.7/site-packages/h5py/_hl/files.py", line 312, in __init__
fid = make_fid(name, mode, userblock_size, fapl, swmr=swmr)
File "/home/share/liuyibing/Anaconda3/envs/py3_torch_v1.4/lib/python3.7/site-packages/h5py/_hl/files.py", line 142, in make_fid
fid = h5f.open(name, flags, fapl=fapl)
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/h5f.pyx", line 78, in h5py.h5f.open
OSError: Unable to open file (file is already open for write (may use <h5clear file> to clear file consistency flags))
这是由于打开h5py的文件后,没有及时关闭file,即file.close()没有调用。所以存在h5py文件flags的不一致性,所以我们直接清理一下该文件的flags即可:bash h5clear -s error_file.h5
Error2
>>> a = h5py.File('trainval_36.h5', 'r')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/share/liuyibing/Anaconda3/envs/py3_torch_v1.4/lib/python3.7/site-packages/h5py/_hl/files.py", line 312, in __init__
fid = make_fid(name, mode, userblock_size, fapl, swmr=swmr)
File "/home/share/liuyibing/Anaconda3/envs/py3_torch_v1.4/lib/python3.7/site-packages/h5py/_hl/files.py", line 142, in make_fid
fid = h5f.open(name, flags, fapl=fapl)
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/h5f.pyx", line 78, in h5py.h5f.open
OSError: Unable to open file (unable to lock file, errno = 11, error message = 'Resource temporarily unavailable')
这个报错和上面情况有些区别,但在我这里都是因为flags引起的。(具体是因为:这个文件在flags不一致的情况下被我移动了)
注意这里 如果直接h5clear将由如下错误:
h5clear error: h5tools_fopen
解决方案也很简单,直接在python下read这个h5py文件,将报错形式换一种,再调用bash h5clear -s error_file.h5
即可解决。
如下所示:
-
打开python的命令端,调用h5py.File(‘file.h5’, ‘r’)
Python 3.7.6 (default, Jan 8 2020, 19:59:22) [GCC 7.3.0] :: Anaconda, Inc. on linux Type "help", "copyright", "credits" or "license" for more information. >>> import h5py >>> a = h5py.File('trainval_36.h5', 'r') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/share/liuyibing/Anaconda3/envs/py3_torch_v1.4/lib/python3.7/site-packages/h5py/_hl/files.py", line 312, in __init__ fid = make_fid(name, mode, userblock_size, fapl, swmr=swmr) File "/home/share/liuyibing/Anaconda3/envs/py3_torch_v1.4/lib/python3.7/site-packages/h5py/_hl/files.py", line 142, in make_fid fid = h5f.open(name, flags, fapl=fapl) 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/h5f.pyx", line 78, in h5py.h5f.open OSError: Unable to open file (file is already open for write (may use <h5clear file> to clear file consistency flags))
-
h5clear
h5clear -s trainval_36.h5