Hello,
I am working on Autonomous Driving - Car Detection,
I got mistake Cannot convert 0.5 to EagerTensor of dtype int64,
after running code in
yolo_filter_boxes(boxes, box_confidence, box_class_probs, threshold = 0.6)
It brings me back on filtering_mask = box_class_scores >= threshold, line of code
1 Like
Please share your full error.
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)
36 # same dimension as box_class_scores, and be True for the boxes you want to keep (with probability >= threshold)
37 ## (≈ 1 line)
—> 38 filtering_mask = box_class_scores >= threshold
39
40 # 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
In your yolo_filter_boxes
function, make sure to use tf.math.argmax
and tf.math.reduce_max
and set the axis to -1.
Yes, that error is fairly common and you can find other threads about it. Most likely you are mixing up the scores (which are floats) and the classes (which are integers). I added some print statements to my code to show the types and shapes of everything and here’s what I see:
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!
What do you see? I’ll bet it’s different and that should point you to which variable is incorrect.
1 Like