def compute_image_anomaly_score(distance):
        """Compute Image-Level Anomaly Score for one nearest_neighbor distance map.
        """
        # distances[n_neighbors, B, HW]
        max_scores = paddle.argmax(distance[0, :])
        confidence = distance[:,
                              max_scores]  # paddle.index_select(distances, max_scores, -1)
        weights = 1 - (paddle.max(paddle.exp(confidence)) /
                       paddle.sum(paddle.exp(confidence)))
        score = weights * paddle.max(distance[0, :])
        return score.item()
Compute Image-Level Anomaly Score for one nearest_neighbor distance map.
        
contrib/QualityInspector/qinspector/uad/models/patchcore.py