From 13505cc7ad9a2edf472fa5f16be583a7fb60eaf7 Mon Sep 17 00:00:00 2001 From: Minh Nguyen Date: Sun, 1 Nov 2026 18:47:28 -0500 Subject: [PATCH 1/5] fix(model): resolve Keras 3 input_shape UserWarning by using explicit Input layer Updated the Sequential model definition to use `tf.keras.Input(shape=(1,))` instead of passing `input_shape` directly to the `Dense` layer, aligning with Keras 3/TensorFlow 2.16+ standards --- .../l02c01_celsius_to_fahrenheit.ipynb | 50 +++---------------- 1 file changed, 7 insertions(+), 43 deletions(-) diff --git a/courses/udacity_intro_to_tensorflow_for_deep_learning/l02c01_celsius_to_fahrenheit.ipynb b/courses/udacity_intro_to_tensorflow_for_deep_learning/l02c01_celsius_to_fahrenheit.ipynb index 7f8ecb29336..da45b572cdc 100644 --- a/courses/udacity_intro_to_tensorflow_for_deep_learning/l02c01_celsius_to_fahrenheit.ipynb +++ b/courses/udacity_intro_to_tensorflow_for_deep_learning/l02c01_celsius_to_fahrenheit.ipynb @@ -167,65 +167,29 @@ "\n", "Next, create the model. We will use the simplest possible model we can, a Dense network. Since the problem is straightforward, this network will require only a single layer, with a single neuron.\n", "\n", - "### Build a layer\n", + "### Build a layer and Assemble it into the model\n", "\n", "We'll call the layer `l0` and create it by instantiating `tf.keras.layers.Dense` with the following configuration:\n", "\n", "* `input_shape=[1]` — This specifies that the input to this layer is a single value. That is, the shape is a one-dimensional array with one member. Since this is the first (and only) layer, that input shape is the input shape of the entire model. The single value is a floating point number, representing degrees Celsius.\n", "\n", - "* `units=1` — This specifies the number of neurons in the layer. The number of neurons defines how many internal variables the layer has to try to learn how to solve the problem (more later). Since this is the final layer, it is also the size of the model's output — a single float value representing degrees Fahrenheit. (In a multi-layered network, the size and shape of the layer would need to match the `input_shape` of the next layer.)\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "pRllo2HLfXiu" - }, - "outputs": [], - "source": [ - "l0 = tf.keras.layers.Dense(units=1, input_shape=[1])" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "_F00_J9duLBD" - }, - "source": [ - "### Assemble layers into the model\n", - "\n", - "Once layers are defined, they need to be assembled into a model. The Sequential model definition takes a list of layers as an argument, specifying the calculation order from the input to the output.\n", + "* `units=1` — This specifies the number of neurons in the layer. The number of neurons defines how many internal variables the layer has to try to learn how to solve the problem (more later). Since this is the final layer, it is also the size of the model's output — a single float value representing degrees Fahrenheit. (In a multi-layered network, the size and shape of the layer would need to match the `input_shape` of the next layer.)\n", "\n", - "This model has just a single layer, l0." + "* Once layers are defined, they need to be assembled into a model. The Sequential model definition takes a list of layers as an argument, specifying the calculation order from the input to the output." ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "id": "cSp-GpLSuMRq" + "id": "pRllo2HLfXiu" }, "outputs": [], "source": [ - "model = tf.keras.Sequential([l0])" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "t7pfHfWxust0" - }, - "source": [ - "**Note**\n", - "\n", - "You will often see the layers defined inside the model definition, rather than beforehand:\n", - "\n", - "```python\n", "model = tf.keras.Sequential([\n", - " tf.keras.layers.Dense(units=1, input_shape=[1])\n", - "])\n", - "```" + " tf.keras.Input(shape=(1,)),\n", + " tf.keras.layers.Dense(units=1)\n", + "])" ] }, { From 2f0863b4e935f0ad06fb6330368e7feadc4ab9ea Mon Sep 17 00:00:00 2001 From: Minh Nguyen Date: Wed, 4 Nov 2026 14:04:35 -0500 Subject: [PATCH 2/5] fix: convert input list to numpy array for model.predict Resolve 'ValueError: Unrecognized data type' in Keras 3 by wrapping the input prediction list `[100.0]` into a NumPy array `np.array([100.0])`. --- .../l02c01_celsius_to_fahrenheit.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/courses/udacity_intro_to_tensorflow_for_deep_learning/l02c01_celsius_to_fahrenheit.ipynb b/courses/udacity_intro_to_tensorflow_for_deep_learning/l02c01_celsius_to_fahrenheit.ipynb index da45b572cdc..ed4ef27c391 100644 --- a/courses/udacity_intro_to_tensorflow_for_deep_learning/l02c01_celsius_to_fahrenheit.ipynb +++ b/courses/udacity_intro_to_tensorflow_for_deep_learning/l02c01_celsius_to_fahrenheit.ipynb @@ -320,7 +320,7 @@ }, "outputs": [], "source": [ - "print(model.predict([100.0]))" + "print(model.predict(np.array([100.0])))" ] }, { From 3e6fcc4de9ed21a506e6a634e5a0569645dbeaea Mon Sep 17 00:00:00 2001 From: Minh Nguyen Date: Wed, 4 Nov 2026 15:30:20 -0500 Subject: [PATCH 3/5] - Change model.predict to use np.array. - refactor: replace input_shape with tf.keras.Input for Keras 3 compatibility --- .../l02c01_celsius_to_fahrenheit.ipynb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/courses/udacity_intro_to_tensorflow_for_deep_learning/l02c01_celsius_to_fahrenheit.ipynb b/courses/udacity_intro_to_tensorflow_for_deep_learning/l02c01_celsius_to_fahrenheit.ipynb index ed4ef27c391..d420a59eb6e 100644 --- a/courses/udacity_intro_to_tensorflow_for_deep_learning/l02c01_celsius_to_fahrenheit.ipynb +++ b/courses/udacity_intro_to_tensorflow_for_deep_learning/l02c01_celsius_to_fahrenheit.ipynb @@ -389,15 +389,17 @@ }, "outputs": [], "source": [ - "l0 = tf.keras.layers.Dense(units=4, input_shape=[1])\n", + "l0 = tf.keras.layers.Dense(units=4)\n", "l1 = tf.keras.layers.Dense(units=4)\n", "l2 = tf.keras.layers.Dense(units=1)\n", - "model = tf.keras.Sequential([l0, l1, l2])\n", + "model = tf.keras.Sequential([\n", + " tf.keras.Input(shape=(1,)),\n", + " l0, l1, l2])\n", "model.compile(loss='mean_squared_error', optimizer=tf.keras.optimizers.Adam(0.1))\n", "model.fit(celsius_q, fahrenheit_a, epochs=500, verbose=False)\n", "print(\"Finished training the model\")\n", - "print(model.predict([100.0]))\n", - "print(\"Model predicts that 100 degrees Celsius is: {} degrees Fahrenheit\".format(model.predict([100.0])))\n", + "print(model.predict(np.array([100.0])))\n", + "print(\"Model predicts that 100 degrees Celsius is: {} degrees Fahrenheit\".format(model.predict(np.array([100.0]))))\n", "print(\"These are the l0 variables: {}\".format(l0.get_weights()))\n", "print(\"These are the l1 variables: {}\".format(l1.get_weights()))\n", "print(\"These are the l2 variables: {}\".format(l2.get_weights()))" From 750e7de83de782bb811fe8f8ae7065a3495df3cf Mon Sep 17 00:00:00 2001 From: Minh Nguyen Date: Wed, 4 Nov 2026 16:27:54 -0500 Subject: [PATCH 4/5] Install importlib_resources package, which is a dependency for tensorflow_datasets. --- .../l03c01_classifying_images_of_clothing.ipynb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/courses/udacity_intro_to_tensorflow_for_deep_learning/l03c01_classifying_images_of_clothing.ipynb b/courses/udacity_intro_to_tensorflow_for_deep_learning/l03c01_classifying_images_of_clothing.ipynb index 1cc08c3c054..beb6712b44d 100644 --- a/courses/udacity_intro_to_tensorflow_for_deep_learning/l03c01_classifying_images_of_clothing.ipynb +++ b/courses/udacity_intro_to_tensorflow_for_deep_learning/l03c01_classifying_images_of_clothing.ipynb @@ -199,6 +199,15 @@ "We will use 60,000 images to train the network and 10,000 images to evaluate how accurately the network learned to classify images. You can access the Fashion MNIST directly from TensorFlow, using the [Datasets](https://www.tensorflow.org/datasets) API:" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "!pip install importlib_resources" + ] + }, { "cell_type": "code", "execution_count": null, From df5efbcc3b88594961beaaf87f11e2526fbe61d3 Mon Sep 17 00:00:00 2001 From: Minh Nguyen Date: Wed, 4 Nov 2026 16:39:32 -0500 Subject: [PATCH 5/5] Add an explicit tf.keras.Input layer, to the UserWarning about input_shape in the Flatten layer. --- .../l03c01_classifying_images_of_clothing.ipynb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/courses/udacity_intro_to_tensorflow_for_deep_learning/l03c01_classifying_images_of_clothing.ipynb b/courses/udacity_intro_to_tensorflow_for_deep_learning/l03c01_classifying_images_of_clothing.ipynb index beb6712b44d..00a42e0dde2 100644 --- a/courses/udacity_intro_to_tensorflow_for_deep_learning/l03c01_classifying_images_of_clothing.ipynb +++ b/courses/udacity_intro_to_tensorflow_for_deep_learning/l03c01_classifying_images_of_clothing.ipynb @@ -449,7 +449,8 @@ "outputs": [], "source": [ "model = tf.keras.Sequential([\n", - " tf.keras.layers.Flatten(input_shape=(28, 28, 1)),\n", + " tf.keras.Input(shape=(28, 28, 1)),\n", + " tf.keras.layers.Flatten(),\n", " tf.keras.layers.Dense(128, activation=tf.nn.relu),\n", " tf.keras.layers.Dense(10, activation=tf.nn.softmax)\n", "])"