C4_W3 - yolo_filter_boxes

Hello !

I am getting the following error while implementing the yolo_filter_box:

TypeError Traceback (most recent call last)
3 boxes = tf.random.normal([19, 19, 5, 4], mean=1, stddev=4, seed = 1)
4 box_class_probs = tf.random.normal([19, 19, 5, 80], mean=1, stddev=4, seed = 1)
----> 5 scores, boxes, classes = yolo_filter_boxes(boxes, box_confidence, box_class_probs, threshold = 0.5)
6 print("scores[2] = " + str(scores[2].numpy()))
7 print("boxes[2] = " + str(boxes[2].numpy()))

in yolo_filter_boxes(boxes, box_confidence, box_class_probs, threshold)
56 ## (≈ 1 line)
57 print(type(box_class_scores))
—> 58 filtering_mask = box_class_scores >= threshold

/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/gen_math_ops.py in greater_equal(x, y, name)
4053 _result = pywrap_tfe.TFE_Py_FastPathExecute(
4054 _ctx._context_handle, tld.device_name, “GreaterEqual”, name,
→ 4055 tld.op_callbacks, x, y)
4056 return _result
4057 except _core._NotOkStatusException as e:

TypeError: Cannot convert 0.5 to EagerTensor of dtype int64

What is wrong with the float number we are giving for the threshold?



The threshold being a float is not wrong here. But for some reason your box_class_scores has the dtype int64 rather than float. Could you mention how you’re calculating box_class_scores, box_classes, and box_scores?


Hello @XpRienzo

Thanks for your reply!

I have difficulties in this assignment. Here is my code as it is for the moment:

box_scores = [-removed]
box_classes = [-removed]
box_class_scores = [-removed]

The error now is:
InvalidArgumentError: Expected begin, end, and strides to be 1D equal size tensors, but got shapes [1,19,19,5], [1,19,19,5], and [1] instead. [Op:StridedSlice] name: strided_slice/

Here the issue seems to be how you’ve calculated the box_class_scores (cannot exactly slice the scores tensor with the indices from argmax the way you are doing it).

If box_classes are the indices of highest scores along the last (-1) axis, you can directly find those highest scores using a different function similar to the one you used to find box_classes, right? :slight_smile:

1 Like

The one other general thing to watch out for here: if you are trying to bring forward your solution from this exercise in the “original recipe” version of this course, you have to be super careful. They changed the definition of yolo_outputs and the function signature of yolo_filter_boxes. You can’t just “copy/paste” here …

Hello @XpRienzo

this was very confusing for me until I did not solve this problem for hypothetical (6,6) output for 3 boxes and less number of class and followed the computational output on each step.

So I did not get in the beginning why we need separately to use tf.math.argmaxto find a list of classes with max scores and tf.math.reduce_max for finding a list of scores itself.

1 Like

Hello @paulinpaloalto

Sorry for posting a code I deleted it. no pb !

1 Like


I have a question regarding the output shapes:
scores.shape = (1789,)
boxes.shape = (1789, 4)
classes.shape = (1789,)

This means that in our boolean mask 1805 - 1789 = 16 values are False ?
Only in 16 cases it did not detect anything, right ?

Yeah it means we have 16 boxes which did not have high enough score to pass our threshold (so overall less confidence about there being an object, and the class if there is an object) here.


Hi, I faced a similar issue. But solved it

These are the shapes:

shape box_scores: (19, 19, 5, 80) [find scores]
shape box_classes: (19, 19, 5) [index with highest score of each BB]
shape box_class_scores: (19, 19, 5) [highest score of each BB]
shape filtering_mask: (19, 19, 5) [filter to delete boxes below threshold]
shape scores: (1789,)
shape boxes: (1789, 4)
shape classes: (1789,)

BB: Bounding Box
Hope it helps:)


Hi @moody !

Nice job!

1 Like