title: Why can't I open a .h5 file in Python?
body: <p>I am trying to open an.h5 file, but experiencing an OS error.</p>
  <pre><code>import sys
  sys.path.append('..') 
  from unet3d.training import load_old_model
  import tables
  from train_model import config
  
  
  model_file=config[&quot;model_file&quot;] #config[&quot;model_file&quot;] = os.path.abspath(&quot;mc_seg_model.h5&quot;)
  hdf5_file=config[&quot;val_data_file&quot;] #config['val_data_file'] = os.path.abspath(&quot;../data/val_data.h5&quot;)
  
  model = load_old_model(model_file)
  </code></pre>
  <p>load_model function is as follows:</p>
  <pre><code>import math
  from functools import partial
  import pdb
  from keras import backend as K
  from keras.callbacks import ModelCheckpoint, CSVLogger, LearningRateScheduler, ReduceLROnPlateau, EarlyStopping
  from keras.models import load_model
  import tensorflow_addons as tfa
  
  def load_old_model(model_file):
  #     pdb.set_trace()
      print(&quot;Loading pre-trained model&quot;)
      custom_objects = {'dice_coefficient_loss': dice_coefficient_loss, 'dice_coefficient': dice_coefficient,
                        'weighted_dice_coefficient': weighted_dice_coefficient,
                        'weighted_dice_coefficient_loss': weighted_dice_coefficient_loss}
      try:
          #from keras_contrib.layers import InstanceNormalization
          from tfa.layers import InstanceNormalization
          custom_objects[&quot;InstanceNormalization&quot;] = InstanceNormalization
      except ImportError:
          pass
      try:
          return load_model(model_file, custom_objects=custom_objects)
      except ValueError as error:
          if 'InstanceNormalization' in str(error):
              raise ValueError(str(error) + &quot;\n\nPlease install keras-contrib to use InstanceNormalization:\n&quot;
                                            &quot;'pip install git+https://www.github.com/keras-team/keras-contrib.git'&quot;)
          else:
              raise error
  </code></pre>
  <p>When I try to load the model, it throws the following OS error and it is an 'Input/output error'.</p>
  <pre><code>2021-06-16 14:31:38.354199: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudart.so.10.1
  Traceback (most recent call last):
    File &quot;draft.py&quot;, line 35, in &lt;module&gt;
      model = load_old_model(model_file)
    File &quot;../unet3d/training.py&quot;, line 50, in load_old_model
      return load_model(model_file, custom_objects=custom_objects)
    File &quot;/share/apps/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/saving/save.py&quot;, line 182, in load_model
      return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile)
    File &quot;/share/apps/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/saving/hdf5_format.py&quot;, line 173, in load_model_from_hdf5
      model_config = f.attrs.get('model_config')
    File &quot;/share/apps/anaconda3/lib/python3.7/_collections_abc.py&quot;, line 660, in get
      return self[key]
    File &quot;h5py/_objects.pyx&quot;, line 54, in h5py._objects.with_phil.wrapper
    File &quot;h5py/_objects.pyx&quot;, line 55, in h5py._objects.with_phil.wrapper
    File &quot;/share/apps/anaconda3/lib/python3.7/site-packages/h5py/_hl/attrs.py&quot;, line 81, in __getitem__
      attr.read(arr, mtype=htype)
    File &quot;h5py/_objects.pyx&quot;, line 54, in h5py._objects.with_phil.wrapper
    File &quot;h5py/_objects.pyx&quot;, line 55, in h5py._objects.with_phil.wrapper
    File &quot;h5py/h5a.pyx&quot;, line 355, in h5py.h5a.AttrID.read
    File &quot;h5py/_proxy.pyx&quot;, line 58, in h5py._proxy.attr_rw
  OSError: Unable to read attribute (file read failed: time = Wed Jun 16 14:31:42 2021
  , filename = '/data/kfernando/brats20/demo_task3_mcmc/mc_seg_model.h5', file descriptor = 4, errno = 5, error message = 'Input/output error', buf = 0x56126c096440, total read size = 30352, bytes this sub-read = 30352, bytes actually read = 18446744073709551615, offset = 16384)
  </code></pre>
  <p>Can someone please tell me what is causing this error?</p>