question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot load HDF5 model after export

See original GitHub issue

I tried the example of Titanic Survival Prediction from your document and export the model with the following code ,although the model is exported I got numpy error.

model = clf.export_model()
model.save('titanic.h5')

Traceback (most recent call last): File "titanic.py", line 17, in <module> model.save('titanic.h5') File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\keras\engine\network.py", line 1008, in save signatures, options) File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\keras\saving\save.py", line 112, in save_model model, filepath, overwrite, include_optimizer) File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\keras\saving\hdf5_format.py", line 109, in save_model_to_hdf5 save_weights_to_hdf5_group(model_weights_group, model_layers) File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\keras\saving\hdf5_format.py", line 627, in save_weights_to_hdf5_group weight_values = K.batch_get_value(weights) File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\keras\backend.py", line 3270, in batch_get_value return [x.numpy() for x in tensors] File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\keras\backend.py", line 3270, in <listcomp> return [x.numpy() for x in tensors] AttributeError: 'TrackableWeightHandler' object has no attribute 'numpy'

When I was trying to load the HDF5 model for prediction , errors occurs

model = tf.keras.models.load_model('titanic.h5', custom_objects=ak.CUSTOM_OBJECTS)

Traceback (most recent call last): File "load_model.py", line 4, in <module> model = tf.keras.models.load_model('titanic.h5', custom_objects=ak.CUSTOM_OBJECTS) File "C:\Users\Python\Python37\lib\site-packages\tensorflow_core\python\keras\saving\save.py", line 146, in load_model return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile) File "C:\Users\Python\Python37\lib\site-packages\tensorflow_core\python\keras\saving\hdf5_format.py", line 171, in load_model_from_hdf5 load_weights_from_hdf5_group(f['model_weights'], model.layers) File "C:\Users\Python\Python37\lib\site-packages\tensorflow_core\python\keras\saving\hdf5_format.py", line 668, in load_weights_from_hdf5_group g = f[name] 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 "C:\Users\Python\Python37\lib\site-packages\h5py\_hl\group.py", line 264, 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 (object 'dense' doesn't exist)"

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
nesty92commented, Mar 6, 2020

any news ?

4reactions
mattou78400commented, Apr 19, 2020

Hello,

Is there any update regarding this topic?

I find myself in the same situation…

Thanks!

(tf 2.1)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error loading model weights from .hdf5 in Keras - Stack Overflow
I'm trying to load model weights from an hdf5 file to evaluate on my test set. When I try and load the weights,...
Read more >
Save and load Keras models | TensorFlow Core
Introduction; How to save and load a model; Setup; Whole-model saving & loading. SavedModel format; Keras H5 format. Saving the architecture.
Read more >
How to Save and Load Your Keras Deep Learning Model
In this post, you will discover how to save your Keras models to files and load them up again to make predictions. After...
Read more >
Can't save save/export and load a keras model that uses ...
I'm following the RNN text-generation tutorial with eager execution pretty much line for line. I've trained the model with my own data set...
Read more >
Model saving & serialization APIs - Keras
Saves the model to Tensorflow SavedModel or a single HDF5 file. ... Note that the model weights may have different scoped names after...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found