From c8aec70ac9e0b7e1f068424ee0210b96b6a634a7 Mon Sep 17 00:00:00 2001 From: Sheikh Tanvir Ahmed <110638482+AhVir@users.noreply.github.com> Date: Fri, 18 Jul 2025 00:26:52 +0600 Subject: [PATCH 1/2] Fix model.predict input type in l02c01_celsius_to_fahrenheit.ipynb Fixed incorrect usage of model.predict([100.0]) in the Celsius-to-Fahrenheit example. The original code used a plain Python list, which raises a ValueError because TensorFlow expects a NumPy array or tensor with explicit shape. Replaced it with: model.predict(np.array([100.0])) This helps prevent confusion for beginners following the tutorial and ensures the example runs without error. --- .../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 7f8ecb29336..bd76fc750d1 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 @@ -356,7 +356,7 @@ }, "outputs": [], "source": [ - "print(model.predict([100.0]))" + "print(model.predict(np.array([100.0])))" ] }, { From da8e04e53ed08c97fcf612713c2d509680190417 Mon Sep 17 00:00:00 2001 From: Sheikh Tanvir Ahmed <110638482+AhVir@users.noreply.github.com> Date: Fri, 18 Jul 2025 01:15:57 +0600 Subject: [PATCH 2/2] Fix model.predict input type in l02c01_celsius_to_fahrenheit.ipynb In addition to the original fix, I found other lines in the same notebook where model.predict([100.0]) was incorrectly used. Passing a plain Python list causes a ValueError because TensorFlow expects inputs with explicit shape. Changes made: - Replaced all instances of model.predict([100.0]) with model.predict(np.array([100.0])) Ensured the formatted print example also uses the correct input format. These changes help prevent runtime errors and confusion for beginners following the tutorial. --- .../l02c01_celsius_to_fahrenheit.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 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 bd76fc750d1..107ec1b1cf3 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 @@ -432,8 +432,8 @@ "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()))"