GeomLoss integrates with PyTorch through three main custom layer classes:
SamplesLoss: For weighted point clouds of any dimension.ImagesLoss: For density maps.VolumesLoss: For volumetric segmentation masks.
Each loss class supports three backends depending on the problem scale:
tensorized: For small problems (< 5,000 samples).online: A reference implementation with a linear memory footprint, suitable for finely sampled measures.multiscale: A fast implementation using an octree-like structure for large-scale problems in dimensions $\le 3$.
GeomLoss supports batchwise computations, autograd, and efficient gradient computation.
import torch
from geomloss import SamplesLoss
# Create some large point clouds in 3D
x = torch.randn(100000, 3, requires_grad=True).cuda()
y = torch.randn(200000, 3).cuda()
# Define a Sinkhorn (~Wasserstein) loss between sampled measures
loss = SamplesLoss(loss="sinkhorn", p=2, blur=.05)
L = loss(x, y) # By default, use constant weights = 1/number of samples
g_x, = torch.autograd.grad(L, [x]) # GeomLoss fully supports autograd!