Exercise 4 - yolo_eval error

Hello,
I’m getting this error: InvalidArgumentError: Incompatible shapes: [19,19,5,2] vs. [19,19,5,80] [Op:Mul] That is diffferent from the other cases. I appreciate your help
In Exercise 1 - yolo_filter_boxes, I added some print functions to help me solve . See below
boxes.shape = (19, 19, 5, 4)
box_scores.shape = (19, 19, 5, 80)
box_classses.shape = (19, 19, 5)
box_class_scores.shape = (19, 19, 5)
filtering_mask.shape = (19, 19, 5)
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,)

Here are the shapes that I see when I run the test cell for yolo_filter_boxes:

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'>
sum(filtering_mask) = 1789
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!

Everything you show looks the same. But then where does that exception message come from? There is nothing we see that has shape [19,19,5,2]. So what variable is it that is triggering that exception?

Thanks Paul
Can I send you a direct message with a screen shot ?

Thanks,

Manny

Sure, that is a way to share code privately.

Paul,
I’m including a screen shot of the error


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()))

in yolo_eval(yolo_outputs, image_shape, max_boxes, score_threshold, iou_threshold)
33 # Use one of the functions you’ve implemented to perform Score-filtering with a threshold of score_threshold (≈1 line)
34
—> 35 scores, boxes, classes = yolo_filter_boxes(boxes, box_confidence, box_class_probs, score_threshold)
36
37 # Scale boxes back to original image shape.

in yolo_filter_boxes(boxes, box_confidence, box_class_probs, threshold)
25 ##(≈ 1 line)
26
—> 27 box_scores = box_confidence * box_class_probs
28
29 print("boxes.shape = " + str(boxes.shape))

/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/math_ops.py in binary_op_wrapper(x, y)
1123 with ops.name_scope(None, op_name, [x, y]) as name:
1124 try:
→ 1125 return func(x, y, name=name)
1126 except (TypeError, ValueError) as e:
1127 # Even if dispatching the op failed, the RHS may be a tensor aware

/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/math_ops.py in _mul_dispatch(x, y, name)
1455 return sparse_tensor.SparseTensor(y.indices, new_vals, y.dense_shape)
1456 else:
→ 1457 return multiply(x, y, name=name)
1458
1459

/opt/conda/lib/python3.7/site-packages/tensorflow/python/util/dispatch.py in wrapper(*args, **kwargs)
199 “”“Call target, and fall back on dispatchers if there is a TypeError.”“”
200 try:
→ 201 return target(*args, **kwargs)
202 except (TypeError, ValueError):
203 # Note: convert_to_eager_tensor currently raises a ValueError, not a

/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/math_ops.py in multiply(x, y, name)
507 “”"
508
→ 509 return gen_math_ops.mul(x, y, name)
510
511

/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/gen_math_ops.py in mul(x, y, name)
6164 return _result
6165 except _core._NotOkStatusException as e:
→ 6166 _ops.raise_from_not_ok_status(e, name)
6167 except _core._FallbackException:
6168 pass

/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/ops.py in raise_from_not_ok_status(e, name)
6841 message = e.message + (" name: " + name if name is not None else “”)
6842 # pylint: disable=protected-access
→ 6843 six.raise_from(core._status_to_exception(e.code, message), None)
6844 # pylint: enable=protected-access
6845

/opt/conda/lib/python3.7/site-packages/six.py in raise_from(value, from_value)

InvalidArgumentError: Incompatible shapes: [19,19,5,2] vs. [19,19,5,80] [Op:Mul]

Ok, well that answers my first question: which variable is wrong. It’s box_confidence. So how is that computed and why is it the wrong shape?

I added print statements in my yolo_eval code right before the call to yolo_filter_boxes and here’s what I see:

box_confidence.shape (19, 19, 5, 1)
box_class_probs.shape (19, 19, 5, 80)
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'>
sum(filtering_mask) = 1786
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 why is your box_confidence the wrong shape? It’s just part of the input data to yolo_eval, right? Oh, wait, did you copy a solution off GitHub? If you did, you have to be super careful: they changed the definition of some of the APIs here in April 2021. If you copy a solution from before that, it doesn’t work. Of course it’s also cheating, so if that’s happened, then maybe you get what you deserved. :laughing: Sorry if I’m jumping to the wrong conclusion here.

Thanks Paul,

My box_confidence.shape = (19, 19, 5, 1) same that yours (See print).
Same as yours box_confidence.shape (19, 19, 5, 1). Appreciate your help

Ok, well then why does that line above throw this exception:

You tell me. Maybe it’s time to just look at your code, but I’ll bet it’s that you copied a solution from the internet which is old and defines the data differently.

Please check your DMs for a message from me.