hollance / BlazeFace-PyTorch

The BlazeFace face detector model implemented in PyTorch
Other
430 stars 91 forks source link

infinite loop in _weighted_non_max_suppression #15

Closed f-izzat closed 1 year ago

f-izzat commented 1 year ago

the loop

        while len(remaining) > 0:
            detection = detections[remaining[0]]

            # Compute the overlap between the first box and the other 
            # remaining boxes. (Note that the other_boxes also include
            # the first_box.)
            first_box = detection[:4]
            other_boxes = detections[remaining, :4]
            ious = overlap_similarity(first_box, other_boxes)

            # If two detections don't overlap enough, they are considered
            # to be from different faces.
            mask = ious > self.min_suppression_threshold
            overlapping = remaining[mask]
            remaining = remaining[~mask]

            # Take an average of the coordinates from the overlapping
            # detections, weighted by their confidence scores.
            weighted_detection = detection.clone()
            if len(overlapping) > 1:
                coordinates = detections[overlapping, :16]
                scores = detections[overlapping, 16:17]
                total_score = scores.sum()
                weighted = (coordinates * scores).sum(dim=0) / total_score
                weighted_detection[:16] = weighted
                weighted_detection[16] = total_score / len(overlapping)

            output_detections.append(weighted_detection)

is infinite if len(remaining) == 1. I faced this when remaining = tensor([1]). Should it not be while len(remaining) > 1. Note this case occured when i set the min_score and min_suppression thresholds to 0.172, 0.104 respectively (if thats of any use)

hollance commented 1 year ago

Thanks for the report, but this is an old repo that I am no longer maintaining.

IIRC this code was translated from MediaPipe's C++ implementation, so perhaps they fixed this bug already (of course, it could also be a bug I introduced by translating the code wrong).