UFuncTypeError: Saliency Maps

Good day, I get this error message and I am unsure how to fix it

"102 # save the normalized tensor image to a file. this is already provided for you.
→ 103 salient_image_name = prefix + image
104 normalized_tensor = tf.expand_dims(normalized_tensor, -1)
105 normalized_tensor = tf.io.encode_jpeg(normalized_tensor, quality=100, format=‘grayscale’)

UFuncTypeError: ufunc ‘add’ did not contain a loop with signature matching types (dtype(’<U32’), dtype(’<U32’)) → dtype(’<U32’)"

Hello,

The error means what you are adding are not of the same type. Check what you are adding.

Thanks, I am hesitant to change code that was already given but I converted the image variable to a string, and the error disappeared.

However, after training my model , I get an accuracy of 81% - which is expected after reading through posts. Upon submission of “images.zip”, I am unable to see the similarity score. I get this error - “There was a problem grading your submission. Check stderr for more details.”

I have changed browsers and it gives the same error

There must be something wrong with your solution. Paste the entire error here maybe I can pick up something. Also i dont suggest changing code thats is given either.

“There was a problem grading your submission. Check stderr for more details.” This is the error that I am getting on Coursera and I am not sure how to see further details after uploading the zip file.

After training for 3 epochs, I get the following images: image




Do these look right?

Im not sure about the images should look like, have a look Post on this post should be similar to your case. Make sure you are following the steps as instructed and not loading any weights not given to you.

Okay thanks. I have done as suggested. I think the problem is with Coursera. Weeks 3 and 4 gave similar issues when uploading. To test this for week 4, I uploaded an empty zip folder with the same name and it gave me the same error - “There was a problem grading your submission. Check stderr for more details.” I also tried uploading a single image and it said " Grader Error: Grader feedback not found." I will have to contact them again

Okay so I traced the issue back to how the image was resized.

I used - which is incorrect:
tf.image.resize(img,(300,300))
img = img/255

And should have used:
img = tf.image.resize(img,(300,300))
img = img/255

A silly mistake which I overlooked

1 Like

I got this same error when running my code in the section " Generate saliency maps with untrained model". it appears to be caused by a portion of the code in the do_salient function that was provided for us. I’m not sure what it means or what to do about it but my code did output the expected images.

here is the complete error:

UFuncTypeError Traceback (most recent call last)
in ()
12 # do_salience(item, model, 1, prefix)
13
—> 14 do_salience(‘dog2.jpg’, model, 1, prefix)

in do_salience(image, model, label, prefix)
109
110 # save the normalized tensor image to a file. this is already provided for you.
→ 111 salient_image_name = prefix + image
112 normalized_tensor = tf.expand_dims(normalized_tensor, -1)
113 normalized_tensor = tf.io.encode_jpeg(normalized_tensor, quality=100, format=‘grayscale’)

UFuncTypeError: ufunc ‘add’ did not contain a loop with signature matching types (dtype(’<U7’), dtype(‘float64’)) → None

As I said above it appears to be caused by a bit of the code in the do_salient function that was provided for us (the part that saves the normalized tensor to file). this is obviously a problem for me because it prevents me from zipping the images for grading. Daniel’s solution doesn’t seem to help me because i already have the resize section of the code written correctly.

2 Likes

okay, I figured out the problem. I had used ‘image’ as a variable name in the body of my do_salient function, so when the provided code later tried to use it to save the image it was no longer what was expected.

3 Likes

thanks, I did the same thing