When creating a post, please add:
- Week # must be added in the tags option of the post.
- Link to the classroom item you are referring to:
- Description (include relevant info but please do not post solution code or your entire notebook):
When I run the ‘Generate saliency maps with an untrained model’ code cell, an error occurs as shown in the screenshot. How can I resolve this? Please guide me.
Please help me, someone. I’ve been stuck here for so long and don’t know how to overcome it.
@Deepti_Prasad Can you please help me?
@Alavudeen_Ahamed
What is that sailent img name??
also you seem to have edited out some of the codes based on the error screenshot
The code in question comes with the below instruction
# normalize the pixel values to be in the range [0, 255].
# the max value in the grayscale tensor will be pushed to 255.
# the min value will be pushed to 0.
# Use the formula: 255 * (x - min) / (max - min)
# Use tf.reduce_max, tf.reduce_min
# Cast the tensor as a tf.uint8
Notice the instruction which mentions use the formula, apply the same formula and cast the tensor to the formula you write.
1.so grayscale_tensor is your x and min as mentions to be pushed to 0, you use the tf.reduce_min to the grayscale_tensor.
- Same way apply to the (max-min), remember here for max you need to use tf.reduce_max to the grayscale_tensor and min again tf.reduce_min to the grayscale_tensor.
Now point 1 and point 2 mentions need to be placed according to the formula you are suppose to use in a single line, i.e.
255 * (point 1)/(point 2)
To the above formula you are suppose to apply
tf.cast(255 * (point1)/(point2))
I mentioning here the formula as pointers as I cannot give you direct answer, but you are suppose to incorporate the explained pointers in the formula to get the normalized_tensor.
Please don’t hard code the paths when you are suppose to write a code. path is only required where it is clearly mentioned otherwise please follow the instructions given when you first open the assignment from the classroom page.
Also for successful submission avoid doing any editing outside the ###START AND END.CODE HERE###
@Deepti_Prasad
I added the image names as ‘cat1.jpg’, ‘cat2.jpg’, and so on, and I also coded the normalized_tensor
according to the instructions, but it still isn’t working.
Shall I send screenshots of my code for your reference?
You have added the datatype which was not required.
Also if you are encountering any new error, then post the screenshot of the new error you have encountered.
Chances are your other codes in the do salience might need correction.
and if you have edited too much of codes, then I would advised to get a fresh copy and restart the codes by only following the instructions given to write the codes
When I removed the
dtype
, an error occurred, as shown in the screenshot.
Do not post codes on public post threadscodes deleted by moderator
@Deepti_Prasad
Apologies for posting code on a public thread.
I got a fresh copy and redid all the code. I also removed the
dtype
in the
normalized_tensor
section. However, an error occurred, as shown in the screenshot.
this error is probably issue from the gradient tape.
please DM me screenshot of the complete do salience grade cells codes
sorry @Alavudeen_Ahamed
that tf.uint8 was supposed to be used to the normalized tensor. I mixed up with other codes.
Another thing after removal of dimension code, I didnt see codes for the below instructions
# plot the normalized tensor
# Set the figure size to 8 by 8
# do not display the axis
# use the 'gray' colormap
# This code is provided for you
Although your codes are correct print(prediction) need to be mentioned after the prediction code
Also make sure you have the codes correctly placed.
after you check all this,
disconnect and restart the kernel. Then run each cell from beginning one by one, let me know if you are still encountering the same error
v
I’ve followed your instructions, but the same error still occurs.
the image recall you convert and then resize recall those step by img,
The reason I want you to recall it as img instead of image is because the code recall might be mixing up images when you add an extra dimension, it might be using the unconverted file
So for the below code lines use img
1.Read the image and convert channel order from BGR to RGB
-
Resize the image to 300 x 300 and normalize pixel values to the range [0, 1]
img =
-
Add an additional dimension (for the batch), and save this in a new variable
images = np.expand_dims( Here use the resize recall img)
@Deepti_Prasad
Now the issue is resolved, and I got the expected output. Thank you so much for your guidance!
1 Like
the use of argument image was preventing the data conversion as the previous steps conversion and resizing was not considered when you recalled codes with local variables.
The idea of local variables or arguments is usually to use it in code recall and not use it to name a code step.
Keep Learning!!!
1 Like