metrics.py
cpas_toolbox.metrics ¶
Metrics for shape evaluation.
diameter ¶
Compute largest Euclidean distance between any two points.
PARAMETER | DESCRIPTION |
---|---|
points_gt |
set of true
|
p_norm |
which Minkowski p-norm is used for distance and nearest neighbor query
|
Returns: Ratio of reconstructed points with closest ground truth point closer than threshold (in p-norm).
Source code in cpas_toolbox/metrics.py
mean_accuracy ¶
mean_accuracy(
points_gt: np.ndarray,
points_rec: np.ndarray,
p_norm: int = 2,
normalize: bool = False,
) -> float
Compute accuracy metric.
Accuracy metric is the same as the mean pointwise distance (or asymmetric chamfer distance) from rec to gt.
See, for example, Occupancy Networks Learning 3D Reconstruction in Function Space, Mescheder et al., 2019.
PARAMETER | DESCRIPTION |
---|---|
points_gt |
set of true points, expected shape (N,3)
TYPE:
|
points_rec |
set of reconstructed points, expected shape (M,3)
TYPE:
|
p_norm |
which Minkowski p-norm is used for distance and nearest neighbor query
TYPE:
|
normalize |
whether to divide result by Euclidean extent of points_gt
TYPE:
|
Returns: Arithmetic mean of p-norm from reconstructed points to closest (in p-norm) ground truth points.
Source code in cpas_toolbox/metrics.py
mean_completeness ¶
mean_completeness(
points_gt: np.ndarray,
points_rec: np.ndarray,
p_norm: int = 2,
normalize: bool = False,
) -> float
Compute completeness metric.
Completeness metric is the same as the mean pointwise distance (or asymmetric chamfer distance) from gt to rec.
See, for example, Occupancy Networks Learning 3D Reconstruction in Function Space, Mescheder et al., 2019.
PARAMETER | DESCRIPTION |
---|---|
points_gt |
set of true points, expected shape (N,3)
TYPE:
|
points_rec |
set of reconstructed points, expected shape (M,3)
TYPE:
|
p_norm |
which Minkowski p-norm is used for distance and nearest neighbor query
TYPE:
|
normalize |
whether to divide result by Euclidean extent of points_gt
TYPE:
|
Returns: Arithmetic mean of p-norm from ground truth points to closest (in p-norm) reconstructed points.
Source code in cpas_toolbox/metrics.py
symmetric_chamfer ¶
symmetric_chamfer(
points_gt: np.ndarray,
points_rec: np.ndarray,
p_norm: int = 2,
normalize: bool = False,
) -> float
Compute symmetric chamfer distance.
There are various slightly different definitions for the chamfer distance.
Note that completeness and accuracy are themselves sometimes referred to as chamfer distances, with symmetric chamfer distance being the combination of the two.
Chamfer L1 in the literature (see, for example, Occupancy Networks Learning 3D Reconstruction in Function Space, Mescheder et al., 2019) refers to using arithmetic mean (note that this is actually differently scaled from L1) when combining accuracy and completeness.
PARAMETER | DESCRIPTION |
---|---|
points_gt |
set of true points, expected shape (N,3)
TYPE:
|
points_rec |
set of reconstructed points, expected shape (M,3)
TYPE:
|
p_norm |
which Minkowski p-norm is used for distance and nearest neighbor query
TYPE:
|
normalize |
whether to divide result by Euclidean extent of points_gt
TYPE:
|
Returns: Arithmetic mean of accuracy and completeness metrics using the specified p-norm.
Source code in cpas_toolbox/metrics.py
normalized_average_distance ¶
normalized_average_distance(
points_gt: np.ndarray, points_rec: np.ndarray, p_norm: int = 2
) -> float
Compute the maximum of the directed normalized average distances.
PARAMETER | DESCRIPTION |
---|---|
points_gt |
set of true points, expected shape (N,3)
TYPE:
|
points_rec |
set of reconstructed points, expected shape (M,3)
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
float
|
Maximum of normalized mean accuracy and mean completeness metrics using the |
float
|
specified p-norm. |
Source code in cpas_toolbox/metrics.py
completeness_thresh ¶
completeness_thresh(
points_gt: np.ndarray,
points_rec: np.ndarray,
threshold: float,
p_norm: int = 2,
normalize: bool = False,
) -> float
Compute thresholded completion metric.
See FroDO: From Detections to 3D Objects, Rünz et al., 2020.
PARAMETER | DESCRIPTION |
---|---|
points_gt |
set of true points, expected shape (N,3)
TYPE:
|
points_rec |
set of reconstructed points, expected shape (M,3)
TYPE:
|
threshold |
distance threshold to count a point as correct
TYPE:
|
p_norm |
which Minkowski p-norm is used for distance and nearest neighbor query
TYPE:
|
normalize |
whether to divide distances by Euclidean extent of points_gt
TYPE:
|
Returns: Ratio of ground truth points with closest reconstructed point closer than threshold (in p-norm).
Source code in cpas_toolbox/metrics.py
accuracy_thresh ¶
accuracy_thresh(
points_gt: np.ndarray,
points_rec: np.ndarray,
threshold: float,
p_norm: int = 2,
normalize: bool = False,
) -> float
Compute thresholded accuracy metric.
See FroDO: From Detections to 3D Objects, Rünz et al., 2020.
PARAMETER | DESCRIPTION |
---|---|
points_gt |
set of true points, expected shape (N,3)
TYPE:
|
points_rec |
set of reconstructed points, expected shape (M,3)
TYPE:
|
threshold |
distance threshold to count a point as correct
TYPE:
|
p_norm |
which Minkowski p-norm is used for distance and nearest neighbor query
TYPE:
|
normalize |
whether to divide distances by Euclidean extent of points_gt
TYPE:
|
Returns: Ratio of reconstructed points with closest ground truth point closer than threshold (in p-norm).
Source code in cpas_toolbox/metrics.py
reconstruction_fscore ¶
reconstruction_fscore(
points_gt: np.ndarray,
points_rec: np.ndarray,
threshold: float,
p_norm: int = 2,
normalize: bool = False,
) -> float
Compute reconstruction fscore.
See What Do Single-View 3D Reconstruction Networks Learn, Tatarchenko, 2019
PARAMETER | DESCRIPTION |
---|---|
points_gt |
set of true points, expected shape (N,3)
TYPE:
|
points_rec |
set of reconstructed points, expected shape (M,3)
TYPE:
|
threshold |
distance threshold to count a point as correct
TYPE:
|
p_norm |
which Minkowski p-norm is used for distance and nearest neighbor query
TYPE:
|
normalize |
whether to divide distances by Euclidean extent of points_gt
TYPE:
|
Returns: Harmonic mean of precision (thresholded accuracy) and recall (thresholded completeness).
Source code in cpas_toolbox/metrics.py
iou_3d_sampling ¶
iou_3d_sampling(
p1: np.ndarray,
r1: Rotation,
e1: np.ndarray,
p2: np.ndarray,
r2: Rotation,
e2: np.ndarray,
num_points: int = 10000,
) -> float
Compute 3D IoU of oriented bounding boxes by sampling the smaller bounding box.
PARAMETER | DESCRIPTION |
---|---|
p1 |
Center position of first bounding box, shape (3,).
TYPE:
|
r1 |
Orientation of first bounding box. This is the rotation that rotates points from bounding box to camera frame.
TYPE:
|
e1 |
Extents (i.e., side lengths) of first bounding box, shape (3,).
TYPE:
|
p2 |
Center position of second bounding box, shape (3,).
TYPE:
|
r2 |
Orientation of second bounding box. This is the rotation that rotates points from bounding box to camera frame.
TYPE:
|
e2 |
Extents (i.e., side lengths) of second bounding box, shape (3,).
TYPE:
|
num_points |
Number of points to sample in smaller bounding box.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
float
|
Approximate intersection-over-union for the two oriented bounding boxes. |
Source code in cpas_toolbox/metrics.py
iou_3d ¶
iou_3d(
p1: np.ndarray,
r1: Rotation,
e1: np.ndarray,
p2: np.ndarray,
r2: Rotation,
e2: np.ndarray,
) -> float
Compute 3D IoU of oriented bounding boxes analytically.
Code partly based on https://github.com/google-research-datasets/Objectron/. Implementation uses half-space intersection instead of Sutherland-Hodgman algorithm.
PARAMETER | DESCRIPTION |
---|---|
p1 |
Center position of first bounding box, shape (3,).
TYPE:
|
r1 |
Orientation of first bounding box. This is the rotation that rotates points from bounding box to camera frame.
TYPE:
|
e1 |
Extents (i.e., side lengths) of first bounding box, shape (3,).
TYPE:
|
p2 |
Center position of second bounding box, shape (3,).
TYPE:
|
r2 |
Orientation of second bounding box. This is the rotation that rotates points from bounding box to camera frame.
TYPE:
|
e2 |
Extents (i.e., side lengths) of second bounding box, shape (3,).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
float
|
Accurate intersection-over-union for the two oriented bounding boxes. |
Source code in cpas_toolbox/metrics.py
correct_thresh ¶
correct_thresh(
position_gt: np.ndarray,
position_prediction: np.ndarray,
orientation_gt: Rotation,
orientation_prediction: Rotation,
extent_gt: Optional[np.ndarray] = None,
extent_prediction: Optional[np.ndarray] = None,
points_gt: Optional[np.ndarray] = None,
points_prediction: Optional[np.ndarray] = None,
position_threshold: Optional[float] = None,
degree_threshold: Optional[float] = None,
iou_3d_threshold: Optional[float] = None,
fscore_threshold: Optional[float] = None,
nad_threshold: Optional[float] = None,
rotational_symmetry_axis: Optional[int] = None,
) -> int
Classify a pose prediction as correct or incorrect.
PARAMETER | DESCRIPTION |
---|---|
position_gt |
Ground truth position, shape (3,).
TYPE:
|
position_prediction |
Predicted position, shape (3,).
TYPE:
|
position_threshold |
Position threshold in meters, no threshold if None.
TYPE:
|
orientation_gt |
Ground truth orientation. This is the rotation that rotates points from bounding box to camera frame.
TYPE:
|
orientation_prediction |
Predicted orientation. This is the rotation that rotates points from bounding box to camera frame.
TYPE:
|
extent_gt |
Bounding box extents, shape (3,). Only used if IoU threshold specified.
TYPE:
|
extent_prediction |
Bounding box extents, shape (3,). Only used if IoU threshold specified.
TYPE:
|
point_gt |
Set of true points, shape (N,3).
|
points_rec |
Set of reconstructed points, shape (M,3).
|
degree_threshold |
Orientation threshold in degrees, no threshold if None.
TYPE:
|
iou_3d_threshold |
3D IoU threshold, no threshold if None.
TYPE:
|
nad_threshold |
Normalized average distance thresold, no threshold if None.
TYPE:
|
rotational_symmetry_axis |
Specify axis along which rotation is ignored. If None, no axis is ignored. 0 for x-axis, 1 for y-axis, 2 for z-axis.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
int
|
1 if error is below all provided thresholds. 0 if error is above one provided |
int
|
threshold. |
Source code in cpas_toolbox/metrics.py
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 |
|