HDF5 file created with h5py can't be opened by h5py

后端 未结 2 1245
长情又很酷
长情又很酷 2020-12-09 17:01

I created an HDF5 file apparently without any problems, under Ubuntu 12.04 (32bit version), using Anaconda as Python distribution and writing in ipython notebooks. The under

相关标签:
2条回答
  • 2020-12-09 17:44

    I was working with https://github.com/matterport/Mask_RCNN and produced the same Error:

        Traceback (most recent call last):
      File "detection.py", line 42, in <module>
        model.load_weights(model_path, by_name=True)
      File "/home/michael/Bachelor/important/Cable-detection/Mask_RCNN-2.1/samples/cable/mrcnn/model.py", line 2131, in load_weights
        f = h5py.File(filepath, mode='r')
      File "/home/michael/.local/lib/python3.6/site-packages/h5py/_hl/files.py", line 271, in __init__
        fid = make_fid(name, mode, userblock_size, fapl, swmr=swmr)
      File "/home/michael/.local/lib/python3.6/site-packages/h5py/_hl/files.py", line 101, in make_fid
        fid = h5f.open(name, flags, fapl=fapl)
      File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper (/tmp/pip-s_7obrrg-build/h5py/_objects.c:2840)
      File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper (/tmp/pip-s_7obrrg-build/h5py/_objects.c:2798)
      File "h5py/h5f.pyx", line 78, in h5py.h5f.open (/tmp/pip-s_7obrrg-build/h5py/h5f.c:2117)
    OSError: Unable to open file (Addr overflow, addr = 800, size=8336, eoa=2144)
    HDF5: infinite loop closing library
          D,T,F,FD,P,FD,P,FD,P,E,E,SL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL
    

    The solution above worked for me too. I interrupted the training at a random point, therefor the .hdf5 file was not closed properly and could not be opened afterward.

    0 讨论(0)
  • 2020-12-09 17:46

    Since we resolved the issue in the comments on my question, I'm writing the results out here to mark it as solved.

    The main problem was that I forgot to close the file after I created it. There would have been two simple options, either:

    import numpy as np
    import h5py
    
    f = h5py.File('myfile.hdf5','w')
    group = f.create_group('a_group')
    group.create_dataset(name='matrix', data=np.zeros((10, 10)), chunks=True, compression='gzip')
    f.close()
    

    or, my favourite because the file is closed automatically:

    import numpy as np
    import h5py
    
    with h5py.File('myfile.hdf5','w') as f:
        group = f.create_group('a_group')
        group.create_dataset(name='matrix', data=np.zeros((10, 10)), chunks=True, compression='gzip')
    
    0 讨论(0)
提交回复
热议问题