C4W3 Assingment 1 : yolo_non_max_suppression, assertion error

Hi, I’m having some truble with yolo_non_max_suppression function in assignment 1 of the week 3.
The error is:

AssertionError Traceback (most recent call last)
in
25 scores2, boxes2, classes2 = yolo_non_max_suppression(scores, boxes, classes, iou_threshold = 0.15)
26
—> 27 assert np.allclose(scores2.numpy(), [0.855]), f"Wrong value on scores {scores2.numpy()}"
28 assert np.allclose(boxes2.numpy(), [[0.45, 0.2, 1.01, 2.6]]), f"Wrong value on boxes {boxes2.numpy()}"
29 assert np.array_equal(classes2.numpy(), [0]), f"Wrong value on classes {classes2.numpy()}"

AssertionError: Wrong value on scores [0.855 0.828]

I read some previous topics about this argument.
Calling tf.image.non_max_suppression, the “iou_threshold” parameter is set to 0.5.
The parameters of tf.gather seem to be in the correct order.

What could be the problem?

If you are hard-coding the iou_threshold to 0.5 on the call to the TF NMS function, that is mistake. That is just the declared default value in the wrapper function. What if the test case passes a different value?

Defining a function is a very different thing than calling a function, right?

Take a look at the test cases: they all pass values different than 0.5, right? So hard-coding that value will not end well. :nerd_face:

Thank you for your answer,
removing 0.5 i get another error:

InvalidArgumentError Traceback (most recent call last)
in
14 assert np.array_equal(classes2.numpy(), [0, 1]), f"Wrong value on classes {classes2.numpy()}"
15
—> 16 scores2, boxes2, classes2 = yolo_non_max_suppression(scores, boxes, classes, iou_threshold = 0.1)
17
18 assert np.allclose(scores2.numpy(), [0.855, 0.828]), f"Wrong value on scores {scores2.numpy()}"

in yolo_non_max_suppression(scores, boxes, classes, max_boxes, iou_threshold)
56 # Append the resulting boxes into the partial result
57 # Use tf.gather() with ‘selected_indices’ and nms_indices_label
—> 58 nms_indices.append( tf.gather( nms_indices_label, selected_indices ) )#, validate_indices=None, axis=None, batch_dims=0, name=None) )
59
60 # Flatten the list of indices and concatenate

/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/array_ops.py in gather_v2(params, indices, validate_indices, axis, batch_dims, name)
4693 name=name,
4694 axis=axis,
→ 4695 batch_dims=batch_dims)
4696
4697

/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/array_ops.py in gather(failed resolving arguments)
4676 return params.sparse_read(indices, name=name)
4677 except AttributeError:
→ 4678 return gen_array_ops.gather_v2(params, indices, axis, name=name)
4679
4680

/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/gen_array_ops.py in gather_v2(params, indices, axis, batch_dims, name)
3843 return _result
3844 except _core._NotOkStatusException as e:
→ 3845 _ops.raise_from_not_ok_status(e, name)
3846 except _core._FallbackException:
3847 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: indices[0] = 1 is not in [0, 1) [Op:GatherV2]

Hmmm, I’m not sure error would cause that. Maybe it’s time to look at your code. We can’t do that on a public thread, but please check your DMs for a message from me. You can recognize DMs in your feed by the envelope icon.

Oh, sorry, I didn’t look closely enough at that exception trace. You can see the tf.gather code there and it is incorrect. Please think again about the meaning of the arguments on that call.

I just solved,
thanks so much!

1 Like

That’s great news that you were able to find the solution based on that hint. Onward! :nerd_face: