From eefeda2fcfda3e8e47024e9af159916baf46d71f Mon Sep 17 00:00:00 2001 From: Alex Olson Date: Tue, 28 Oct 2025 20:20:37 -0400 Subject: [PATCH] Fix resize scale bug in lab_4.ipynb - Add scaling by 255 after skimage.transform.resize to convert from [0,1] to [0,255] range - ResNet50 preprocess_input expects [0,255] range, not [0,1] range - Fixes incorrect predictions caused by wrong preprocessing - Applied to both cat image classification and webcam exercise cells - Students still implement preprocess_input and predict steps themselves --- 01_materials/labs/lab_4.ipynb | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/01_materials/labs/lab_4.ipynb b/01_materials/labs/lab_4.ipynb index 90bd4fffb..49316d21a 100644 --- a/01_materials/labs/lab_4.ipynb +++ b/01_materials/labs/lab_4.ipynb @@ -603,7 +603,17 @@ "outputs": [], "source": [ "from keras.applications.resnet50 import preprocess_input, decode_predictions\n", - "\n" + "\n", + "# Resize the image\n", + "input_image = resize(image, (224, 224, 3), mode='reflect', anti_aliasing=True)\n", + "\n", + "# Scale to [0, 255] range (resize returns [0, 1])\n", + "input_image = input_image * 255\n", + "\n", + "# Prepare for model (add batch dimension)\n", + "input_image = np.expand_dims(input_image, axis=0)\n", + "\n", + "# Now use preprocess_input and predict to classify the image\n" ] }, { @@ -680,7 +690,20 @@ "id": "b1pXoFQgI_fk" }, "outputs": [], - "source": [] + "source": [ + "# Apply the same preprocessing as before and classify the webcam image\n", + "\n", + "# Resize the image\n", + "input_image = resize(image, (224, 224, 3), mode='reflect', anti_aliasing=True)\n", + "\n", + "# Scale to [0, 255] range (resize returns [0, 1])\n", + "input_image = input_image * 255\n", + "\n", + "# Prepare for model (add batch dimension)\n", + "input_image = np.expand_dims(input_image, axis=0)\n", + "\n", + "# Now use preprocess_input and predict to classify the image\n" + ] }, { "cell_type": "code",