All lerf-changes moved to projects-lerf, except viewer changes

This commit is contained in:
Chung Min Kim committed 2023-03-31 23:11:14 +00:00
1 parent 18208f7aaa
commit a87b7c3b53
6 files changed
+52 -43

No files matched your search

+31
View File
@@ -0,0 +1,31 @@
import torch
from torch import nn
from torchtyping import TensorType
class CLIPRenderer(nn.Module):
"""Calculate CLIP embeddings along ray."""
@classmethod
def forward(
cls,
embeds: TensorType["bs":..., "num_samples", "num_classes"],
weights: TensorType["bs":..., "num_samples", 1],
) -> TensorType["bs":..., "num_classes"]:
"""Calculate semantics along the ray."""
output = torch.sum(weights * embeds, dim=-2)
output = output / torch.linalg.norm(output, dim=-1, keepdim=True)
return output
class MeanRenderer(nn.Module):
"""Calculate average of embeddings along ray."""
@classmethod
def forward(
cls,
embeds: TensorType["bs":..., "num_samples", "num_classes"],
weights: TensorType["bs":..., "num_samples", 1],
) -> TensorType["bs":..., "num_classes"]:
"""Calculate semantics along the ray."""
output = torch.sum(weights * embeds, dim=-2)
return output