当前位置: 首页 > news >正文

【3D入门-指标篇下】 3D重建评估指标对比-附实现代码

3D重建评估指标对比表

每个指标的具体代码位于文章末尾

指标计算方法数值范围评估重点优缺点适用场景
Chamfer Distance (C1)从预测网格到真实网格的平均距离[0, +∞)几何形状准确性优点:直观、计算高效
缺点:对噪声敏感
整体形状评估
Chamfer Distance (C2)从真实网格到预测网格的平均距离[0, +∞)几何形状完整性优点:检测缺失部分
缺点:可能被异常值影响
完整性评估
Normal Consistency对应点法向量点积的平均值[0, 1]表面细节质量优点:反映表面光滑度
缺点:不关注几何形状
表面质量评估
F-Score基于距离阈值的精确率/召回率调和平均[0, 100]高精度区域占比优点:关注高精度区域
缺点:依赖阈值选择
精度评估
Bounding Box IoU边界框交集体积/并集体积[0, 1]整体形状重叠度优点:计算简单快速
缺点:忽略细节差异
粗略形状评估

详细指标说明

1. Chamfer Distance (C1 & C2)

# C1: 预测→真实
c1 = np.mean(dist_pred_to_gt) * 1000# C2: 真实→预测  
c2 = np.mean(dist_gt_to_pred) * 1000

特点对比

  • C1:检测预测网格中多余的部分
  • C2:检测预测网格中缺失的部分
  • 理想情况:C1 ≈ C2,且都接近0

2. Normal Consistency

normal_consistency = np.mean(normal_pred_to_gt) + np.mean(normal_gt_to_pred)

评估维度

  • 表面光滑度:法向量变化是否平滑
  • 细节保持:能否保持原始表面的细节特征
  • 方向一致性:表面朝向是否一致

3. F-Score

tau = 1e-2  # 1cm阈值
prec_tau = (dist_pred_to_gt <= tau).mean() * 100
recall_tau = (dist_gt_to_pred <= tau).mean() * 100
fscore = (2 * prec_tau * recall_tau) / (prec_tau + recall_tau)

评估重点

  • 高精度区域:关注距离小于1cm的区域
  • 平衡性:同时考虑精确率和召回率
  • 实用性:反映实际应用中的可用性

4. Bounding Box IoU

iou = inter_vol / (vol1 + vol2 - inter_vol)

评估范围

  • 整体形状:不考虑内部细节
  • 空间位置:反映整体定位准确性
  • 尺度一致性:检测尺寸是否合理

指标组合使用建议

评估目标推荐指标组合原因
整体质量C1 + C2 + F-Score全面评估几何准确性
表面质量Normal Consistency专注表面细节
快速筛选Bounding Box IoU计算快速,适合大规模筛选
高精度应用F-Score关注高精度区域
研究对比全部指标提供全面的评估维度

实际应用中的选择

  • 服装重建:重点关注C1、C2和Normal Consistency
  • 快速原型:使用Bounding Box IoU进行初步筛选
  • 生产应用:重点关注F-Score确保高精度
  • 学术研究:使用全部指标进行综合评估

这些指标各有侧重,组合使用能够全面评估3D重建的质量。

import os 
import torch
import scipy as sp
import numpy as np
import argparse
import trimeshfrom tqdm import tqdm   def compute_iou_bbox(mesh, gt_mesh):mesh_bounds = mesh.boundsgt_mesh_bounds = gt_mesh.boundsxx1 = np.max([mesh_bounds[0, 0], gt_mesh_bounds[0, 0]])yy1 = np.max([mesh_bounds[0, 1], gt_mesh_bounds[0, 1]])zz1 = np.max([mesh_bounds[0, 2], gt_mesh_bounds[0, 2]])xx2 = np.min([mesh_bounds[1, 0], gt_mesh_bounds[1, 0]])yy2 = np.min([mesh_bounds[1, 1], gt_mesh_bounds[1, 1]])zz2 = np.min([mesh_bounds[1, 2], gt_mesh_bounds[1, 2]])vol1 = (mesh_bounds[1, 0] - mesh_bounds[0, 0]) * (mesh_bounds[1, 1] - mesh_bounds[0, 1]) * (mesh_bounds[1, 2] -mesh_bounds[0, 2])vol2 = (gt_mesh_bounds[1, 0] - gt_mesh_bounds[0, 0]) * (gt_mesh_bounds[1, 1] - gt_mesh_bounds[0, 1]) * (gt_mesh_bounds[1, 2] -gt_mesh_bounds[0, 2])inter_vol = np.max([0, xx2 - xx1]) * np.max([0, yy2 - yy1]) * np.max([0, zz2 - zz1])iou = inter_vol / (vol1 + vol2 - inter_vol + 1e-11)return ioudef calculate_iou(gt, prediction):intersection = torch.logical_and(gt, prediction)union = torch.logical_or(gt, prediction)return torch.sum(intersection) / torch.sum(union)def compute_surface_metrics(mesh_pred, mesh_gt):"""Compute surface metrics (chamfer distance and f-score) for one example.Args:mesh: trimesh.Trimesh, the mesh to evaluate.Returns:chamfer: float, chamfer distance.fscore: float, f-score."""# Chamfereval_points = 100000point_gt, idx_gt = mesh_gt.sample(eval_points, return_index=True)normal_gt = mesh_gt.face_normals[idx_gt]point_gt = point_gt.astype(np.float32)point_pred, idx_pred = mesh_pred.sample(eval_points, return_index=True)normal_pred = mesh_pred.face_normals[idx_pred]point_pred = point_pred.astype(np.float32)dist_pred_to_gt, normal_pred_to_gt = distance_field_helper(point_pred, point_gt, normal_pred, normal_gt)dist_gt_to_pred, normal_gt_to_pred = distance_field_helper(point_gt, point_pred, normal_gt, normal_pred)# TODO: subdivide by 2 following OccNet # https://github.com/autonomousvision/occupancy_networks/blob/406f79468fb8b57b3e76816aaa73b1915c53ad22/im2mesh/eval.py#L136chamfer_l1 = np.mean(dist_pred_to_gt) + np.mean(dist_gt_to_pred)c1 = np.mean(dist_pred_to_gt)c2 = np.mean(dist_gt_to_pred)normal_consistency = np.mean(normal_pred_to_gt) + np.mean(normal_gt_to_pred)# Fscoretau = 1e-2eps = 1e-6#dist_pred_to_gt = (dist_pred_to_gt**2)#dist_gt_to_pred = (dist_gt_to_pred**2)prec_tau = (dist_pred_to_gt <= tau).astype(np.float32).mean() * 100.recall_tau = (dist_gt_to_pred <= tau).astype(np.float32).mean() * 100.fscore = (2 * prec_tau * recall_tau) / max(prec_tau + recall_tau, eps)# Following the tradition to scale chamfer distance up by 10.return c1 * 1000., c2 * 1000., normal_consistency / 2., fscoredef distance_field_helper(source, target, normals_src=None, normals_tgt=None):target_kdtree = sp.spatial.cKDTree(target)distances, idx = target_kdtree.query(source, n_jobs=-1)if normals_src is not None and normals_tgt is not None:normals_src = \normals_src / np.linalg.norm(normals_src, axis=-1, keepdims=True)normals_tgt = \normals_tgt / np.linalg.norm(normals_tgt, axis=-1, keepdims=True)normals_dot_product = (normals_tgt[idx] * normals_src).sum(axis=-1)# Handle normals that point into wrong direction gracefully# (mostly due to mehtod not caring about this in generation)normals_dot_product = np.abs(normals_dot_product)else:normals_dot_product = np.array([np.nan] * source.shape[0], dtype=np.float32)return distances, normals_dot_productdef main(args):input_subfolder =  [x for x in sorted(os.listdir(args.input_path)) if os.path.isdir(os.path.join(args.input_path, x))]gt_subfolder = [x for x in sorted(os.listdir(args.gt_path)) if os.path.isdir(os.path.join(args.gt_path, x))]eval_name = args.input_path.split('/')[-1]mean_c1_list = []mean_c2_list = []mean_fscore_list = []mean_normal_consistency_list = []iou_list = []for pred, gt in tqdm(zip(input_subfolder, gt_subfolder)):pred_path = [x for x in sorted(os.listdir(os.path.join(args.input_path, pred))) ifx.endswith('shoes.obj') and not x.startswith('init')and not x.startswith('.')]if len(pred_path) == 0:continuemesh_pred = trimesh.load(os.path.join(args.input_path, pred, pred_path[0]))gt_path = [x for x in sorted(os.listdir(os.path.join(args.gt_path, gt, 'clothing'))) if x.endswith('shoe.obj')and not x.startswith('.')][0]mesh_gt = trimesh.load(os.path.join(args.gt_path, gt, 'clothing', gt_path))pred_2_scan, scan_2_pred, normal_consistency, fscore = compute_surface_metrics(mesh_pred, mesh_gt)iou = compute_iou_bbox(mesh_pred, mesh_gt)#print('Chamfer: {:.3f}, {:.3f}, Normal Consistency: {:.3f}, Fscore: {:.3f}, IOU: {:.3f}'.format(pred_2_scan, scan_2_pred, normal_consistency, fscore, iou))#print((pred_2_scan + scan_2_pred) / 2.0)iou_list.append(iou)mean_c1_list.append(pred_2_scan)mean_c2_list.append(scan_2_pred)mean_fscore_list.append(fscore)mean_normal_consistency_list.append(normal_consistency)mean_c1 = np.mean(mean_c1_list)mean_c2 = np.mean(mean_c2_list)mean_fscore = np.mean(mean_fscore_list)mean_normal_consistency = np.mean(mean_normal_consistency_list)mean_iou = np.mean(iou_list)std_c1 = np.std(mean_c1_list)std_c2 = np.std(mean_c2_list)std_fscore = np.std(mean_fscore_list)std_normal_consistency = np.std(mean_normal_consistency_list)std_iou = np.std(iou_list)print('Mean Chamfer: {:.3f} ({:.3f}), {:.3f} ({:.3f}), Normal Consistency: {:.3f} ({:.3f}), Fscore: {:.3f} ({:.3f})'.format(mean_c1, std_c1, mean_c2, std_c2, mean_normal_consistency, std_normal_consistency, mean_fscore, std_fscore))print('{:.3f} ({:.3f}),{:.3f} ({:.3f}),{:.3f} ({:.3f}),{:.3f} ({:.3f}),{:.3f} ({:.3f})'.format(mean_c1, std_c1, mean_c2, std_c2, mean_normal_consistency, std_normal_consistency, mean_fscore, std_fscore, mean_iou, std_iou))print('{:.6f}, {:.6f}, {:.6f}, {:.6f}, {:.6f}'.format(mean_c1, mean_c2, mean_normal_consistency, mean_fscore, mean_iou))output_txt = eval_name + '.txt'out = np.stack([mean_c1_list, mean_c2_list, mean_normal_consistency_list, mean_fscore_list], axis=1)np.savetxt(output_txt, out, fmt='%.6f', delimiter=' ')
if __name__ == '__main__':parser = argparse.ArgumentParser()#parser.add_argument('-o', '--output_dir', required=True, help='Where to store the processed images and other data.')parser.add_argument('-i', '--input_path', required=True ,type=str)parser.add_argument('-g', '--gt_path', required=True ,type=str)main(parser.parse_args())
http://www.dtcms.com/a/356924.html

相关文章:

  • SwiGLU激活函数的原理
  • 【原版系统】Windows 11 LTSC 2024
  • Blender中旋转与翻转纹理的实用方法教学
  • Java全栈工程师的面试实战:从技术细节到业务场景
  • 企业级数据库管理实战(三):数据库性能监控与调优的实战方法
  • 达梦数据库-数据缓冲区
  • React前端开发_Day5
  • OCELOT 2023:细胞 - 组织相互作用场景下的细胞检测挑战赛|文献速递-深度学习人工智能医疗图像
  • BSS138-7-F 电子元器件Diodes美台N沟道小信号增强型MOSFET晶体管
  • 基于MCP工具的开发-部署-上线与维护全流程技术实现与应用研究
  • Bert学习笔记
  • CSS scale函数详解
  • 基于BeautifulSoup库的简易爬虫实现:以大学排名为例
  • 【K8s】整体认识K8s之与集群外部访问--service
  • 机器学习回顾——逻辑回归
  • pcl封装6 connection_cloud 提取聚簇后的每个点云
  • 开源vs商用美颜sdk:美白滤镜功能在直播中的优劣对比
  • RoadMP3告别车载音乐烦恼,一键get兼容音频
  • FDTD_mie散射_项目研究(1)
  • 抖音电商首创最严珠宝玉石质检体系,推动行业规范与消费扩容
  • Shader开发(十八)实现纹理滚动效果
  • Shell 脚本基础教程
  • AARRR模型(用户生命周期模型)——用户怎么长大的?
  • 【人工智能99问】GPT4的原理是什么?(32/99)
  • 【备战2025数模国赛】(三)数模常见赛题类型及解决办法
  • 矩池云中LLaMA- Factory多机多卡训练
  • 介绍⼀下Llama的结构
  • 身份证实名认证API集成—身份核验接口-网络平台安全合规
  • GoogLeNet:深度学习中的“卷积网络变形金刚“
  • 安全月报 | 傲盾DDoS攻击防御2025年8月简报