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 1/3] 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", From a7d2c63621b6c85bd1ce92608621d08bcd33315a Mon Sep 17 00:00:00 2001 From: RenuPatelGoogle <89264621+RenuPatelGoogle@users.noreply.github.com> Date: Mon, 16 Oct 2023 23:01:37 +0530 Subject: [PATCH 2/3] Update intro_to_modules.ipynb --- site/en/guide/intro_to_modules.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/site/en/guide/intro_to_modules.ipynb b/site/en/guide/intro_to_modules.ipynb index ef8311e44d5..52d8b69c338 100644 --- a/site/en/guide/intro_to_modules.ipynb +++ b/site/en/guide/intro_to_modules.ipynb @@ -918,8 +918,8 @@ }, "outputs": [], "source": [ - "import keras - "@keras.saving.register_keras_serializable() + "import keras\n", + "@keras.saving.register_keras_serializable()\n", "class MySequentialModel(tf.keras.Model):\n", " def __init__(self, name=None, **kwargs):\n", " super().__init__(**kwargs)\n", From a3c2132f68ecd180887b03685d967cadcbd51ad9 Mon Sep 17 00:00:00 2001 From: RenuPatelGoogle <89264621+RenuPatelGoogle@users.noreply.github.com> Date: Tue, 17 Oct 2023 12:15:21 +0530 Subject: [PATCH 3/3] Update intro_to_modules.ipynb Added keras import on top of the code. --- site/en/guide/intro_to_modules.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/en/guide/intro_to_modules.ipynb b/site/en/guide/intro_to_modules.ipynb index 52d8b69c338..79bbe89ca56 100644 --- a/site/en/guide/intro_to_modules.ipynb +++ b/site/en/guide/intro_to_modules.ipynb @@ -91,6 +91,7 @@ "outputs": [], "source": [ "import tensorflow as tf\n", + "import keras\n", "from datetime import datetime\n", "\n", "%load_ext tensorboard" @@ -918,7 +919,6 @@ }, "outputs": [], "source": [ - "import keras\n", "@keras.saving.register_keras_serializable()\n", "class MySequentialModel(tf.keras.Model):\n", " def __init__(self, name=None, **kwargs):\n",