C4 W3 YOLO Exercise - TypeError: Cannot convert 0.5 to EagerTensor

I get the below error with this exercise. It identifies the filtering mask implementation as the problem but i think i might have botched some code upstream from that line. Any guidance would be appreciated.

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

1 Like

Problem fixed - called the wrong function for box_class_scores.

how did You do ., Iā€™m getting same error

what is the right fucnction?

Use tf.math.reduce_max to compute box_class_scores. You probably used tf.math.argmax, which is what you use to compute box_classes.

2 Likes

Thanks @paulinpaloalto , i cleared all test cases

So, Iā€™m using the correct methods for both items and Iā€™m still getting this error.

Then why does it fail? Maybe you are using the correct functions, but passing them incorrect arguments. Note the details of the error message: itā€™s not just that it canā€™t convert 0.5 to a tensor value. Itā€™s that it canā€™t convert it to an integer tensor value. Note that the classes are integers, but the scores are floating point. Of course this assumes that your error message is exactly the same as that in the OP of this thread. But you havenā€™t actually shown your output ā€¦

Itā€™s the exact same error. I hear what youā€™re saying and appreciate the comment. Iā€™ll definitely investigate further.

Thanks

Debugging is always one step at a time: start from what the error message tells you. So you are comparing a tensor with integer values to 0.5. So how did that happen? Are you using the wrong tensor (classes when it should be scores) or is it that the contents of the tensor are incorrect, meaning that the error is in earlier code. One step at a time ā€¦

2 Likes