Getting error in yolo_non_max_suppression function

I am getting an error in tf.gather(nms_indices_label,selected_indices)
InvalidArgumentError: indices[0] = 1 is not in [0, 1) [Op:GatherV2]
what can be the possible reason?

boxes and scores contain information across all classes. Since we’re performing non-max suppression per label (see here to understand the motivation), the for loop should use boxes and scores for a single label during each pass. Please read the markdown again and look closely at the loop specific variables for invoking non_max_suppression correctly.

As far as tf.gather is concerned, see this as well:

# Append the resulting boxes into the partial result
# Use tf.gather() with 'selected_indices' and `nms_indices_label` 

Posting solution code in a public topic goes against our Community Forum Code of Conduct. It’s okay to share stacktrace on a public post and send code to a mentor via direct message.

Please edit your post.

Here’s a guide on how to edit a post.

2 Likes

Hi,

I am having the same problem and trying to resolve it for past 24 hours.

You mentioned

the for loop should use boxes and scores for a single label during each pass.

How to select boxes and scores for single label? Since, I am new to TF syntax.

They already wrote the logic for you to select one label in each iteration of the loop. Here’s is the first few lines of the template code:

    boxes = tf.cast(boxes, dtype=tf.float32)
    scores = tf.cast(scores, dtype=tf.float32)

    nms_indices = []
    classes_labels = tf.unique(classes)[0] # Get unique classes
    
    for label in classes_labels:
        filtering_mask = classes == label
    
    #### START CODE HERE

So within the loop, the variable label is the current single label value that you are working with and filtering_mask is boolean mask tensor which will be True in the positions that match the current label. Then they give you a pretty big hint in the template code about which TF function to use:

        # Get boxes for this class
        # Use tf.boolean_mask() with 'boxes' and `filtering_mask`
        boxes_label = None
        
        # Get scores for this class
        # Use tf.boolean_mask() with 'scores' and `filtering_mask`
        scores_label = None

Have you read the documentation for TF boolean_mask and gather?

Hi, I have the same error
InvalidArgumentError: indices[0] = 1 is not in [0, 1) [Op:GatherV2]

After reading the solution here, I have adjusted the code to reflect the boxes_label and scores_label but will got the same issue. As i can’t put the code here, is there anyway that a mentor could help me please ?
Thanks so much

I have figured it out that I used the gather function wrongly. all good now thank you

1 Like

Glad to hear you found the error! Yes, it sounds like you probably reversed the arguments in the “gather” call.