From 0ff4b79183baebf14facf9594c414da96be5e1fb Mon Sep 17 00:00:00 2001 From: Raffi Khatchadourian Date: Tue, 1 Sep 2026 15:42:14 -0400 Subject: [PATCH 1/2] Point the image download at a host that still serves it image_transformation.ipynb cannot run past its second cell. The image URL returns 404, so image.jpeg is written from an HTML error page and PIL raises on the next cell. Every transformation in the notebook is downstream of that. Wikimedia Commons has a stable copy of the same photograph. It requires a descriptive User-Agent, so the stock python-requests one draws a 403 and that alone would leave the notebook just as broken. Both are handled here. The original is several thousand pixels on a side, so scale it to 800px wide after loading, which keeps the transformation cells quick. A raise_for_status call turns any future outage into an error at the download rather than a confusing one inside PIL. --- .../5_DataManagement/image_transformation.ipynb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tensorflow_v2/notebooks/5_DataManagement/image_transformation.ipynb b/tensorflow_v2/notebooks/5_DataManagement/image_transformation.ipynb index f2b060a65..bb60007ec 100644 --- a/tensorflow_v2/notebooks/5_DataManagement/image_transformation.ipynb +++ b/tensorflow_v2/notebooks/5_DataManagement/image_transformation.ipynb @@ -43,7 +43,12 @@ "outputs": [], "source": [ "# Download an image.\n", - "d = requests.get(\"https://www.paristoolkit.com/Images/xeffel_view.jpg.pagespeed.ic.8XcZNqpzSj.jpg\")\n", + "# The previous host stopped serving this image. Wikimedia Commons has a stable\n", + "# copy, but requires a descriptive User-Agent rather than the requests default.\n", + "headers = {\"User-Agent\": \"TensorFlow-Examples (https://github.com/aymericdamien/TensorFlow-Examples)\"}\n", + "url = \"https://upload.wikimedia.org/wikipedia/commons/8/85/Tour_Eiffel_Wikimedia_Commons_%28cropped%29.jpg\"\n", + "d = requests.get(url, headers=headers)\n", + "d.raise_for_status()\n", "with open(\"image.jpeg\", \"wb\") as f:\n", " f.write(d.content)" ] @@ -57,6 +62,8 @@ "# Load image to numpy array.\n", "img = PIL.Image.open('image.jpeg')\n", "img.load()\n", + "# Scale to a workable size; the original is several thousand pixels on a side.\n", + "img = img.resize((800, round(800 * img.height / img.width)))\n", "img_array = np.array(img)" ] }, From 206e03e11d9c13aa90b35b35e888a840ca01775a Mon Sep 17 00:00:00 2001 From: Raffi Khatchadourian Date: Tue, 1 Sep 2026 21:25:58 -0400 Subject: [PATCH 2/2] Drop the rescale, and give the download a timeout Two changes from review. The rescale is removed. Resizing the image changes what every transformation cell below it operates on, which is more than repairing a download needs to do, and a notebook demonstrating image transformations should show them on the image it fetched rather than on one this change decided to substitute. The original is large, but that is the notebook's business rather than this fix's. The download gains timeout=30. Without it a stalled connection hangs the cell indefinitely with no output, which in a teaching notebook reads as the example being broken rather than as the network being slow. What remains is only what the notebook cannot run without: a descriptive User-Agent, the URL of a host that still serves the image, and raise_for_status so a future outage surfaces at the download rather than as an unreadable image two cells later. --- .../notebooks/5_DataManagement/image_transformation.ipynb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tensorflow_v2/notebooks/5_DataManagement/image_transformation.ipynb b/tensorflow_v2/notebooks/5_DataManagement/image_transformation.ipynb index bb60007ec..fdd373619 100644 --- a/tensorflow_v2/notebooks/5_DataManagement/image_transformation.ipynb +++ b/tensorflow_v2/notebooks/5_DataManagement/image_transformation.ipynb @@ -47,7 +47,7 @@ "# copy, but requires a descriptive User-Agent rather than the requests default.\n", "headers = {\"User-Agent\": \"TensorFlow-Examples (https://github.com/aymericdamien/TensorFlow-Examples)\"}\n", "url = \"https://upload.wikimedia.org/wikipedia/commons/8/85/Tour_Eiffel_Wikimedia_Commons_%28cropped%29.jpg\"\n", - "d = requests.get(url, headers=headers)\n", + "d = requests.get(url, headers=headers, timeout=30)\n", "d.raise_for_status()\n", "with open(\"image.jpeg\", \"wb\") as f:\n", " f.write(d.content)" @@ -62,8 +62,6 @@ "# Load image to numpy array.\n", "img = PIL.Image.open('image.jpeg')\n", "img.load()\n", - "# Scale to a workable size; the original is several thousand pixels on a side.\n", - "img = img.resize((800, round(800 * img.height / img.width)))\n", "img_array = np.array(img)" ] },