Skip to content

Commit

Permalink
Added few lines of code in Keras Custom model to fix the error
Browse files Browse the repository at this point in the history
Added 2 lines of code `import keras`,
`@keras.saving.register_keras_serializable()` on top of the Keras Custom model definition because it shows typeerror - "Make sure custom classes are decorated with `@keras.saving.register_keras_serializable()`" after reloading the model when saving as `.keras`.

As mentioned in this Saving [Custom objects](https://www.tensorflow.org/guide/keras/serialization_and_saving#custom_objects) definition.

Please refer to this replicated working code [gist](https://colab.research.google.com/gist/RenuPatelGoogle/f124503c52144c5ed6e9c79cffcb593d/intro_to_modules.ipynb#scrollTo=hpW-4Dj3Q1Rb) for your reference. Thank you.
  • Loading branch information
RenuPatelGoogle authored Oct 16, 2023
1 parent c6fe18c commit 348133c
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions site/en/guide/intro_to_modules.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,8 @@
},
"outputs": [],
"source": [
"import keras
"@keras.saving.register_keras_serializable()
"class MySequentialModel(tf.keras.Model):\n",
" def __init__(self, name=None, **kwargs):\n",
" super().__init__(**kwargs)\n",
Expand Down

0 comments on commit 348133c

Please sign in to comment.