Getting error in yolo_non_max_suppression function

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 a 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?

1 Like