Spaces:
Sleeping
Sleeping
File size: 1,961 Bytes
e4bf056 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import numpy as np
from scipy.spatial import cKDTree as KDTree
def completion_ratio(gt_points, rec_points, dist_th=0.05):
gen_points_kd_tree = KDTree(rec_points)
distances, _ = gen_points_kd_tree.query(gt_points)
comp_ratio = np.mean((distances < dist_th).astype(np.float32))
return comp_ratio
def accuracy(gt_points, rec_points, gt_normals=None, rec_normals=None):
gt_points_kd_tree = KDTree(gt_points)
distances, idx = gt_points_kd_tree.query(rec_points)
acc = np.mean(distances)
acc_median = np.median(distances)
if gt_normals is not None and rec_normals is not None:
normal_dot = np.sum(gt_normals[idx] * rec_normals, axis=-1)
normal_dot = np.abs(normal_dot)
return acc, acc_median, np.mean(normal_dot), np.median(normal_dot)
return acc, acc_median
def completion(gt_points, rec_points, gt_normals=None, rec_normals=None):
gt_points_kd_tree = KDTree(rec_points)
distances, idx = gt_points_kd_tree.query(gt_points)
comp = np.mean(distances)
comp_median = np.median(distances)
if gt_normals is not None and rec_normals is not None:
normal_dot = np.sum(gt_normals * rec_normals[idx], axis=-1)
normal_dot = np.abs(normal_dot)
return comp, comp_median, np.mean(normal_dot), np.median(normal_dot)
return comp, comp_median
def compute_iou(pred_vox, target_vox):
# Get voxel indices
v_pred_indices = [voxel.grid_index for voxel in pred_vox.get_voxels()]
v_target_indices = [voxel.grid_index for voxel in target_vox.get_voxels()]
# Convert to sets for set operations
v_pred_filled = set(tuple(np.round(x, 4)) for x in v_pred_indices)
v_target_filled = set(tuple(np.round(x, 4)) for x in v_target_indices)
# Compute intersection and union
intersection = v_pred_filled & v_target_filled
union = v_pred_filled | v_target_filled
# Compute IoU
iou = len(intersection) / len(union)
return iou |