#course4 #week3 #assignment01 Car detection with YOLO

Hi, I am having trouble with the assignment on Car detection, could anyone plese help.
I am at the exercise 3 to yolo_non_max_suppression function, and I got an error from this line:

nms_indices.append(tf.gather(nms_indices_label, selected_indices ))


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)
57 print(selected_indices)
58 print(nms_indices_label)
—> 59 nms_indices.append(tf.gather(nms_indices_label, selected_indices ))
60
61

/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]

1 Like

This line here seems not be entirely correct!

Check the tf.gather  |  TensorFlow v2.3.0 on how to place the arguments inside it properly.

2 Likes

i have this identical error, been stuck here for a few days. Ive tried rearranging the order to nms_indices.append(tf.gather(selected_indices,nms_indices_label)) …but no difference. Not even sure if this is the problem, but the error is identical to original poster tungoc. Should there be any of these parameteres in there? ```
validate_indices=None, axis=None, batch_dims=0, name=None…
The hint said that only params, indices were needed. Thanks in adavance for any help. :pray:

@Cormac_Garvey in
nms indices, I hope you have recalled the scores, boxes and classes separately using the the tf.gather

another thing to check is to make sure you didn’t edit the data type for max boxes tensor.

Also check in yolo filter grade cell, your axis argument is correctly recalled for box classes and box classes score. instruction mentions to use axis of -1. then box classes score, boxes and box classes are used To apply the mask.

check if these were not mixed up.

Hi Deepti, yes i have 3 separate tf.gather() lines for scores, boxes, classes. They all use nms_indices.

Re max_boxes_tensor. There is no max_boxes_tensor. I saw a script on the internet with max_boxes_tensor, so did create it as int32 and try it, but no difference,so removed it. I use max_boxes ( the integer) in the function: nms_indices_label = tf.image.non_max_suppression(…)

in the yolo_filter_boxes() function, i have axis=-1 for box_classes, and also for box_class_scores. This function passed the unit test check. However i had a lot of trouble with this and just had to keep changing the code until it passed, as i couldnt understand the purpose of the variables. Here is what passed the unit test. Is this wrong?
image

can you dm screenshots of all the 3 grade cell by personal dm.

Actually I am not the mentor for this course and I had done this course long back at that time we had max box tensor.

I will add DLS mentor who has access to the updated course.

@paulinpaloalto can you check the learner’s query.

1 Like

Please check your DMs for a message from me.

1 Like

To close the loop on the public thread, there was an error in the loop logic, but it was not the most common one of getting the arguments to tf.gather wrong. The error is that on the TF nms call, the code passes the complete lists of all the boxes and scores, not just the ones for the current label being processed in that iteration.

Hi! How did you fix your code? I have the similar issue for the following line:

{moderator edit - solution code removed}

InvalidArgumentError Traceback (most recent call last)
in
8 print(f"iou: \t{iou(boxes[0], boxes[1])}“)
9
—> 10 scores2, boxes2, classes2 = yolo_non_max_suppression(scores, boxes, classes, iou_threshold = 0.9)
11
12 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)
55 # Append the resulting boxes into the partial result
56 # Use tf.gather() with ‘selected_indices’ and nms_indices_label
—> 57 nms_indices.append(tf.gather(selected_indices, nms_indices_label))
58
59 # 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[1] = 1 is not in [0, 1) [Op:GatherV2]

Your line with “gather” looks correct as it is. Did you read my previous “close the loop” post on this thread?

If that hint doesn’t help, check your DMs for a message from me about how to proceed.