C4W3 ex3 Op:GatherV2 indices

I am stuck on the ‘yolo_non_max_suppression’ function.

I wonder if I need to slice one of the input parameters for tf.image.non_max suppression() call. I have tried both boxes and boxes_labels and get similar error.

nms_indices_label = tf.image.non_max_suppression(
boxes_label, # was boxes
scores_label, # was scores
max_boxes,
iou_threshold=iou_threshold)

upstream, I set
boxes_label = tf.boolean_mask(boxes, filtering_mask)

it fails at —> 63 nms_indices.append(tf.gather(nms_indices_label, selected_indices))

and finally reports an InvalidArgumentError: indices[0] = 1 is not in [0, 1) [Op:GatherV2]

While Getting error in yolo_non_max_suppression function - #2 by balaji.ambresh looks similar, I am not following the path to correcting any mistakes.

Please let me know if i should include more/less code or printed diagnostics.
Thanks, - Colin

(mentor edit - link deleted)
got it. i was looking for the paperclip icon. thanks again. - Colin

Reminder: Please do not post your code on the forum.

For those who find this thread later:

The order of arguments were reversed in one of the function calls inside the yolo_non_max_suppression() function.

Thank you Tom. Flipping the parameters did the trick!

1 Like

TMosh, I got the exactly same error, I think I did the same code as colinPDX, and I switch the parameter (I guess the tf.gather()) around) but it still give the same error. I am particularly confused are the following:

  1. selected_indices = tf.squeeze(tf.where(None), axis=1) this step asks to get Get original indices of the selected boxes, but why we need to call squeez and use tf.where()? there’s no explanation in the exercise
  2. What is the expected shape for nms_indices_label, I always got (1,), so of course when selected_indices become 1 for the second class label which is 1, the system will complain InvalidArgumentError: indices[0] = 1 is not in [0, 1) [Op:GatherV2]

selected_indices is supposed to be a 1D tensor with just the indices of the true values from filtering_mask. Try it with and without the tf.squeeze and see what difference that makes.

For the shape of nms_indices_label, it depends on how many of the entries pass the NMS test, right? That’s the point of all this. It’s hard to use the trivially sized test cases to debug your code. You don’t really see the way things work until you get to the full test case with 54 entries.

Hi, I got the same error. On which function inside the yolo_non_max_suppression() should I flip the arguments?

Check the function definitions, and check that when you call those functions, that you are putting the arguments in the correct order.

I got the error during the unit test. When I check the unit test, the argument order in the function call looks correct. There are 4 function calls in the unit test. I passed the 1st function call. I got the error during the 2nd call where the difference is only the iou_threshold (0.9 for the 1st call and 0.1 for the 2nd call). After some debugging, I solved the problem. Thanks.

2 Likes

That’s great news! Thanks for confirming.

1 Like

What was the debugging you did exactly? I’m getting the same issue for the 2nd call (0.1), but didn’t manage to resolve the issue with the following settings:

nms_indices_label = tf.image.non_max_suppression(
boxes_label,
scores_label,
max_boxes,
iou_threshold=iou_threshold)

Thanks!

There are a lot of other function calls within that function other than the call to the key TF function that you show. I’ve seen 5 or 6 people make the exact same mistake when they call tf.gather to select the corresponding elements that match the nms_indices_label value that is returned from the TF call there. Please find that call and carefully consider how tf.gather works: it uses the second argument as a list of indices to select the desired elements of the first argument.

2 Likes