Car detection with YOLO - yolo_filter_boxes

Hi,

in yolo_filter_boxes, I get the error below and I am struggling to solve it.

I believe it may be related to the type of box_class_scores (I am using tf.math.reduce_max, as per the instructions) but I do not know what I am supposed to do.

Thank you in advance
Matteo


TypeError Traceback (most recent call last)
in
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)
34 # same dimension as box_class_scores, and be True for the boxes you want to keep (with probability >= threshold)
35 ## (≈ 1 line)
—> 36 filtering_mask = tf.math.greater(box_class_scores, threshold)
37
38 # Step 4: Apply the mask to box_class_scores, boxes and box_classes

/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/gen_math_ops.py in greater(x, y, name)
3964 _result = pywrap_tfe.TFE_Py_FastPathExecute(
3965 _ctx._context_handle, tld.device_name, “Greater”, name,
→ 3966 tld.op_callbacks, x, y)
3967 return _result
3968 except _core._NotOkStatusException as e:

TypeError: Cannot convert 0.5 to EagerTensor of dtype int64

Hello @vaccam1

You are almost there, I was also stuck with this for a long time :slight_smile:
please check you filtering mask, it is much easier to implement than you think, there is no additional functions needed :wink:

P.S: please remove your code once you figure this out
hth

5 Likes

I have tried using filtering_mask = box_class_scores >= threshold but still get the error message below. I have tried a myriad of things. I am really stuck and I do not understand how it is possible. Perhaps a mentor could help me out?


TypeError Traceback (most recent call last)
in
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)
34 # same dimension as box_class_scores, and be True for the boxes you want to keep (with probability >= threshold)
35 ## (≈ 1 line)
—> 36 filtering_mask = box_class_scores >= threshold
37
38 # Step 4: Apply the mask to box_class_scores, boxes and box_classes

/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

Hi,

I have made some progress modifying my filtering_mask into:

filtering_mask = None

Now at least I get an output, but with the wrong shapes, for example:

scores.shape = (361, 5, 80)
boxes.shape = (361, 5, 4)
classes.shape = (361, 5)

I strongly believe the issue is still with my filtering mask. Any suggestion would be deeply appreciated (I have already got full marks on the other assignment, so I just need to get this right to move onto the next week!)

1 Like

I got the same problem too. But I solve it now. It seems like your box_class_scores makes a wrong shape, you should use box_score instead of box_classes.
And also your scores will show a wrong value compare to the expected output.
Check the document closely to make sure you fully understand what those function actually working for.

6 Likes

scores = tf.boolean_mask(box_scores, filtering_mask)

I believe the error resides in this line of code. We need to use box_class_scores here instead of box_scores. Try replacing it with,

scores = tf.boolean_mask(box_class_scores, filtering_mask)

2 Likes

Just remember the tf.math.reducemax function is to get the maximum values, tf.math.argmax to get the position of the max value
Screenshot 2021-05-26 211853

4 Likes

You were all correct. I had made a mess and did not realize it at first because I forgot to apply tf.cast in my filtering mask. I will now remove the code above. Thank you all!!!

You were right! It is much easier to implement than we think. Thanks for the help! I was stuck on this for an hour and I figured it out now!

1 Like

@Aravind1999 I am very glad my comment was helpful ! Good luck for the rest !

2 Likes

Hello,

I’m still stuck, and I have the same error you had “Cannot convert 0.5 to EagerTensor of dtype int64”
But the thing is, if we apply the mast to the “box_class_scores” and knowing that “box_class_scores” countain intergers from 1 to 80.

I really don’t get it.

What would be logic for me it to create the filter based on box_classes because its values are between 0 and 1

Please any help would be appreciable

box_class_scores should not contain integers. It should contain floats. The classes are integers, though. I thought we already covered this on the other thread where you asked about this function.

I’m sorry I posted this here before creating the othder thread.