Skip to content

Output intermediate Chamfer distribution score to get F-Score metric. #733

@gaetan-landreau

Description

@gaetan-landreau

🚀 Feature

NOTE: Allow in the chamfer_distance() function from pytorch3d.loss.chamfer to also output intermediate values of cham_x and cham_y in order to being able for instance to compute F-score metric.

cham_dist = cham_x + cham_y

Motivation

It would be great to have this feature in order to directly infer the F-score from these cham_x and cham_y distributions since F-Score & Chamfer distance are two useful metrics in 3D reconstruction for instance.

Pitch

Adding this feature would allow to easily compute F-score metric, in a similar fashion way as @ThibaultGROUEIX did in one of his repo: https://github.com/ThibaultGROUEIX/ChamferDistancePytorch

import torch

def fscore(dist1, dist2, threshold=0.001):
    """
    Calculates the F-score between two point clouds with the corresponding threshold value.
    :param dist1: Batch, N-Points
    :param dist2: Batch, N-Points
    :param th: float
    :return: fscore, precision, recall
    """
    # NB : In this depo, dist1 and dist2 are squared pointcloud euclidean distances, so you should adapt the threshold accordingly.
    precision_1 = torch.mean((dist1 < threshold).float(), dim=1)
    precision_2 = torch.mean((dist2 < threshold).float(), dim=1)
    fscore = 2 * precision_1 * precision_2 / (precision_1 + precision_2)
    fscore[torch.isnan(fscore)] = 0
    return fscore, precision_1, precision_2

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions