MCPcopy Create free account
hub / github.com/InternRobotics/G2VLM / find_best_alignment

Function find_best_alignment

modeling/pi3/utils/basic.py:152–188  ·  view source on GitHub ↗

找出将 gt_normal 调整为 pred_normal 的最佳操作。 参数: - gt_normal: Tensor of shape (N, 3),GT 法向量。 - pred_normal: Tensor of shape (N, 3),预测的法向量。 返回: - best_perm: 最佳的 xyz 轴顺序 (例如 (0, 1, 2))。 - best_signs: 最佳的符号调整 (例如 [1, -1, 1])。 - best_error: 调整后的最小误差。

(gt_normal, pred_normal)

Source from the content-addressed store, hash-verified

150
151
152def find_best_alignment(gt_normal, pred_normal):
153 """
154 找出将 gt_normal 调整为 pred_normal 的最佳操作。
155
156 参数:
157 - gt_normal: Tensor of shape (N, 3),GT 法向量。
158 - pred_normal: Tensor of shape (N, 3),预测的法向量。
159
160 返回:
161 - best_perm: 最佳的 xyz 轴顺序 (例如 (0, 1, 2))。
162 - best_signs: 最佳的符号调整 (例如 [1, -1, 1])。
163 - best_error: 调整后的最小误差。
164 """
165 # 所有可能的轴顺序排列
166 permutations = list(itertools.permutations([0, 1, 2]))
167 # 所有可能的符号组合 (+1, -1)
168 signs = list(itertools.product([1, -1], repeat=3))
169
170 best_error = float('inf')
171 best_perm = None
172 best_signs = None
173
174 for perm in permutations:
175 for sign in signs:
176 # 调整 gt_normal 的顺序和符号
177 transformed_gt = gt_normal[:, perm] * torch.tensor(sign, device=gt_normal.device)
178
179 # 计算 L2 范数误差
180 error = torch.norm(transformed_gt - pred_normal, dim=1).mean().item()
181
182 # 更新最佳结果
183 if error < best_error:
184 best_error = error
185 best_perm = perm
186 best_signs = sign
187
188 return best_perm, best_signs, best_error
189
190
191def get_robust_pca(features: torch.Tensor, m: float = 2, remove_first_component=False):

Callers

nothing calls this directly

Calls 1

normMethod · 0.80

Tested by

no test coverage detected