Error importing .h5 file of neural network in Google Colab using keras load_model()

52 views Asked by At

I'm trying to import my model into Google Colab from my Drive. I have saved it using the built-in model.save() method:

singleMachineModel.save('singleMachineModel.h5')

And here is the code I'm trying in Colab to load it, after mounting my drive:

modelFilePath = '/content/drive/MyDrive/Matt/Codes/MILP_stochastic/singleMachineModel.h5'

from keras.models import load_model
model = load_model(modelFilePath)

I've done this before and it has worked fine, but not I get the error:

OSError                                   Traceback (most recent call last)
<ipython-input-9-2e91c67b5404> in <cell line: 6>()
      4 from keras.models import load_model
      5 # @@@ Need to set path properly
----> 6 model = load_model(modelFilePath)
      7 print("Trained")
      8 

3 frames
/usr/local/lib/python3.10/dist-packages/h5py/_hl/files.py in make_fid(name, mode, userblock_size, fapl, fcpl, swmr)
    229         if swmr and swmr_support:
    230             flags |= h5f.ACC_SWMR_READ
--> 231         fid = h5f.open(name, flags, fapl=fapl)
    232     elif mode == 'r+':
    233         fid = h5f.open(name, h5f.ACC_RDWR, fapl=fapl)

h5py/_objects.pyx in h5py._objects.with_phil.wrapper()

h5py/_objects.pyx in h5py._objects.with_phil.wrapper()

h5py/h5f.pyx in h5py.h5f.open()

OSError: Unable to open file (file signature not found)

I've tried uploading directly to the environment but the issue persists. The code works fine in Spyder, so I think the files are saved correctly and that corruption shouldn't be an issue. The path is correct, so I would expect it to run without erring.

0

There are 0 answers