Course 4 Week 3: Car detection - yolo-eval ValueError

I’m getting this error on yolo eval function. Do you have any hint how to fix it?

ValueError: operands could not be broadcast together with shapes (19,19,5,4) (19,19,5,80)

When you get a dimension mismatch, the first question is what shapes should they be? Which one is the incorrect one? Then how did it turn out that way? Here is the output that I get from the test cell for yolo_eval with print statements added to show the shape and type of most of the intermediate values:

boxes.shape (19, 19, 5, 4)
boxes.dtype <dtype: 'float32'>
box_scores.shape (19, 19, 5, 80)
box_scores.dtype <dtype: 'float32'>
box_classes.shape (19, 19, 5)
box_classes.dtype <dtype: 'int64'>
box_class_scores.shape (19, 19, 5)
box_class_scores.dtype <dtype: 'float32'>
filtering_mask.shape (19, 19, 5)
filtering_mask.dtype <dtype: 'bool'>
scores[2] = 171.60194
boxes[2] = [-1240.3483 -3212.5881  -645.78    2024.3052]
classes[2] = 16
scores.shape = (10,)
boxes.shape = (10, 4)
classes.shape = (10,)
 All tests passed!

So which line of code is actually “throwing”? Based on what I show above, you should have the first step in figuring this out …

I have the same problem:
InvalidArgumentError: Incompatible shapes: [19,19,5,4] vs. [19,19,5,80] [Op:Mul]
InvalidArgumentError Traceback (most recent call last)
in
5 tf.random.normal([19, 19, 5, 1], mean=1, stddev=4, seed = 1),
6 tf.random.normal([19, 19, 5, 80], mean=1, stddev=4, seed = 1))
----> 7 scores, boxes, classes = yolo_eval(yolo_outputs)
8 print("scores[2] = " + str(scores[2].numpy()))
9 print("boxes[2] = " + str(boxes[2].numpy()))

scores.shape = (10,)
boxes.shape = (10, 4)
classes.shape = (10,)

can you give us another hint please?

You haven’t shown us the whole exception trace. That is just the call to yolo_eval, not the actual line that “throws”. You have to start debugging from the actual exception, right? What are the operands in the failing operation? Then work backwards to figure out why the shapes don’t match.

Actually my guess would be that the error is actually getting thrown in yolo_filter_boxes, which is called from yolo_eval. If your yolo_filter_boxes passed the previous tests, then most likely you just have the arguments wrong when you call it from yolo_eval. FWIW a lot of the print output I showed above came from my yolo_filter_boxes function. Here’s the output from the test call for that function:

boxes.shape (19, 19, 5, 4)
boxes.dtype <dtype: 'float32'>
box_scores.shape (19, 19, 5, 80)
box_scores.dtype <dtype: 'float32'>
box_classes.shape (19, 19, 5)
box_classes.dtype <dtype: 'int64'>
box_class_scores.shape (19, 19, 5)
box_class_scores.dtype <dtype: 'float32'>
filtering_mask.shape (19, 19, 5)
filtering_mask.dtype <dtype: 'bool'>
scores[2] = 9.270486
boxes[2] = [ 4.6399336  3.2303846  4.431282  -2.202031 ]
classes[2] = 8
scores.shape = (1789,)
boxes.shape = (1789, 4)
classes.shape = (1789,)
 All tests passed!

One other general thing to note here: if you are using code that you wrote on an earlier version of the course (from before the April 2021 “refresh”), they changed the function signatures of several of the functions here. You can’t just “copy/paste” your solutions forward and expect it to work. Careful comparison of the function definitions and the order of the return values is required. :nerd_face:

thank you, this was the right hint. I had not the correct order of the values. Now it works.