mrdbourke / tensorflow-deep-learning

All course materials for the Zero to Mastery Deep Learning with TensorFlow course.
https://dbourke.link/ZTMTFcourse
MIT License
5.05k stars 2.5k forks source link

Notebook 09: load_model fails on saved model from 09. SkimLit Milestone Project 2 #523

Closed wallaceturner closed 1 year ago

wallaceturner commented 1 year ago

recreate:

!wget https://storage.googleapis.com/ztm_tf_course/skimlit/skimlit_tribrid_model.zip
!mkdir skimlit_gs_model
!unzip skimlit_tribrid_model.zip -d skimlit_gs_model
loaded_model = tf.keras.models.load_model('skimlit_gs_model/skimlit_tribrid_model/')
AssertionError                            Traceback (most recent call last)
[<ipython-input-114-204ece70eaf7>](https://localhost:8080/#) in <module>
----> 1 loaded_model = tf.keras.models.load_model('skimlit_gs_model/skimlit_tribrid_model/')
      2 loaded_model.summary()

1 frames
[/usr/local/lib/python3.8/dist-packages/tensorflow/python/checkpoint/checkpoint.py](https://localhost:8080/#) in assert_existing_objects_matched(self)
    850       # Display max number of 10 variables in error message.
    851       num_variables_to_show = min(10, num_unused_python_objects)
--> 852       raise AssertionError(
    853           f"Found {num_unused_python_objects} Python objects that were "
    854           "not bound to checkpointed values, likely due to changes in the "

AssertionError: Found 1 Python objects that were not bound to checkpointed values, likely due to changes in the Python program. Showing 1 of 1 unmatched objects: [<tensorflow.python.ops.lookup_ops.MutableHashTable object at 0x7f523de00c40>]
mrdbourke commented 1 year ago

Hi @wallaceturner ,

Thank you for this.

Looks like it was an error with the original saved model and an older version of TensorFlow.

Have fixed this in an update and the above code should work now:

# Download pretrained model from Google Storage
!wget https://storage.googleapis.com/ztm_tf_course/skimlit/skimlit_tribrid_model.zip
!mkdir skimlit_gs_model
!unzip skimlit_tribrid_model.zip -d skimlit_gs_model

See the full (updated May 2023) notebook: https://github.com/mrdbourke/tensorflow-deep-learning/blob/main/09_SkimLit_nlp_milestone_project_2.ipynb

See a couple of API updates to the notebook too: https://github.com/mrdbourke/tensorflow-deep-learning/discussions/557