Reload the images in case you run this cell multiple times
(training_images, _), _ = tf.keras.datasets.mnist.load_data(path=data_path)
Apply your function
training_images = reshape_and_normalize(training_images)
print(f"Maximum pixel value after normalization: {np.max(training_images)}\n")
print(f"Shape of training set after reshaping: {training_images.shape}\n")
print(f"Shape of one image after reshaping: {training_images[0].shape}")
Here is error message
NameError Traceback (most recent call last)
in
3
4 # Apply your function
----> 5 training_images = reshape_and_normalize(training_images)
6
7 print(f"Maximum pixel value after normalization: {np.max(training_images)}\n")
in reshape_and_normalize(images)
6
7 # Reshape the images to add an extra dimension
----> 8 training_images = training_image.reshape(60000,28,28,1)
9 training_images = np.expand_dims(training_images, axis =-1)
10 # Normalize pixel values
NameError: name ātraining_imageā is not defined
@Chris.X @paulinpaloalto
@Chris.X please kindly help me outā
Hey @KINGSLEY_TOM
You can DM me the source code of your homework as before then we can inspect it, thanks.

Your profile is now hiddenā
@KINGSLEY_TOM I guess now you can. Basically, you can attach the code in the thread so that other guys can also see and give suggestions.
Is that line in a loop? That could explain why that reference is to training_image
but elsewhere itās always training_images
with a trailing s. The 60000 first dimension suggests to me they should all be the same but I donāt have the rest of the code.
You misspelled the name of the variable, right? training_image is not the same as training_images.
Also note that you filed this under āGeneral Discussionsā, so itās really not clear which course you are talking about. Youāll generally have better luck getting answers if you file things under the relevant categories. Note that you can edit that using the little āedit pencilā on the title. Iād offer to move it for you, but I donāt recognize which course this is from.
Likely TF Developer Professional Certificate. TF1 W3
@KINGSLEY_TOM One of your other posts had an error due to leading Upper Case where it should have been lower, while this one truncates the last character. This level of attention to detail is critical and given this pattern, I recommend that you devote some time to close inspection of variable names whenever you get unexpected results.
2 Likes