|
import torch |
|
import torch.nn as nn |
|
import torch.nn.functional as F |
|
import numpy as np |
|
import math |
|
|
|
|
|
def chamfer(x, y): |
|
x = x[:, None].repeat(1, y.shape[1], 1, 1) |
|
y = y[:, :, None].repeat(1, 1, x.shape[2], 1) |
|
dis = torch.norm(x - y, 2, dim=-1) |
|
dis_xy = torch.mean(dis.min(dim=2).values, dim=1) |
|
dis_yx = torch.mean(dis.min(dim=1).values, dim=1) |
|
return dis_xy + dis_yx |
|
|
|
|
|
def batch_chamfer_dist(xyz, xyz_gt): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
xyz_gt = xyz_gt[None] |
|
dist1 = torch.sqrt(torch.sum((xyz[:, :, None] - xyz_gt[:, None]) ** 2, dim=3)) |
|
dist2 = torch.sqrt(torch.sum((xyz_gt[:, None] - xyz[:, :, None]) ** 2, dim=3)) |
|
chamfer = torch.mean(torch.min(dist1, dim=1).values, dim=1) + torch.mean(torch.min(dist2, dim=1).values, dim=1) |
|
return chamfer |
|
|
|
|
|
def angle_normalize(x): |
|
return (((x + math.pi) % (2 * math.pi)) - math.pi) |
|
|
|
|
|
def clip_actions(action, action_lower_lim, action_upper_lim): |
|
action_new = action.clone() |
|
|
|
action_new.data.clamp_(action_lower_lim, action_upper_lim) |
|
return action_new |
|
|