From 348133c102a4b915c301cb08c44aaf91dba13f40 Mon Sep 17 00:00:00 2001 From: RenuPatelGoogle <89264621+RenuPatelGoogle@users.noreply.github.com> Date: Mon, 16 Oct 2023 22:56:42 +0530 Subject: [PATCH] Added few lines of code in Keras Custom model to fix the error 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. --- site/en/guide/intro_to_modules.ipynb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/site/en/guide/intro_to_modules.ipynb b/site/en/guide/intro_to_modules.ipynb index 1bedb87e894..ef8311e44d5 100644 --- a/site/en/guide/intro_to_modules.ipynb +++ b/site/en/guide/intro_to_modules.ipynb @@ -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",