-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlosses.py
More file actions
21 lines (16 loc) · 833 Bytes
/
losses.py
File metadata and controls
21 lines (16 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import torch
import torch.nn.functional as F
def eikonal_loss(gradients):
# TODO (Q6): Implement eikonal loss
id = torch.ones(gradients.shape[0]).to("cuda:0")
loss = torch.square(torch.norm(gradients, dim=-1) - id)
return loss.mean()
def sphere_loss(signed_distance, points, radius=1.0):
return torch.square(signed_distance[..., 0] - (torch.norm(points, dim=-1) - radius)).mean()
def get_random_points(num_points, bounds, device):
min_bound = torch.tensor(bounds[0], device=device).unsqueeze(0)
max_bound = torch.tensor(bounds[1], device=device).unsqueeze(0)
return torch.rand((num_points, 3), device=device) * (max_bound - min_bound) + min_bound
def select_random_points(points, n_points):
points_sub = points[torch.randperm(points.shape[0])]
return points_sub.reshape(-1, 3)[:n_points]