torchtyping => jaxtyping (#1838)

* Run `ruff --fix`

* Add jaxtyping migration script

* Run migration scripts + ruff + black

* Merge remote-tracking branch 'origin/main' into brent/jaxtyping

* black

* Fix lint

* fix lint

* Cleanup and more specific types

* Fixed annotation errors

* Fix more errors

* Fix annotation

* Delete _torchtyping_to_jaxtyping.py

---------

Co-authored-by: Matt Tancik <mattt4001@gmail.com>
This commit is contained in:
Brent YiandMatt Tancik authored and GitHub committed 2023-05-16 15:57:47 -07:00
1 parent 9b6290ea43
commit 6ba2a18b2b
65 files changed
+597 -531

No files matched your search

+16 -15
View File
@@ -28,8 +28,9 @@ import numpy as np
import pymeshlab
import torch
import torch.nn.functional as F
from jaxtyping import Bool, Float
from skimage import measure
from torchtyping import TensorType
from torch import Tensor
from nerfstudio.exporter.exporter_utils import Mesh, render_trajectory
from nerfstudio.pipelines.base_pipeline import Pipeline
@@ -44,17 +45,17 @@ class TSDF:
Class for creating TSDFs.
"""
voxel_coords: TensorType[3, "xdim", "ydim", "zdim"]
voxel_coords: Float[Tensor, "3 xdim ydim zdim"]
"""Coordinates of each voxel in the TSDF."""
values: TensorType["xdim", "ydim", "zdim"]
values: Float[Tensor, "xdim ydim zdim"]
"""TSDF values for each voxel."""
weights: TensorType["xdim", "ydim", "zdim"]
weights: Float[Tensor, "xdim ydim zdim"]
"""TSDF weights for each voxel."""
colors: TensorType["xdim", "ydim", "zdim", 3]
colors: Float[Tensor, "xdim ydim zdim 3"]
"""TSDF colors for each voxel."""
voxel_size: TensorType[3]
voxel_size: Float[Tensor, "3"]
"""Size of each voxel in the TSDF. [x, y, z] size."""
origin: TensorType[3]
origin: Float[Tensor, "3"]
"""Origin of the TSDF [xmin, ymin, zmin]."""
truncation_margin: float = 5.0
"""Margin for truncation."""
@@ -86,7 +87,7 @@ class TSDF:
return truncation
@staticmethod
def from_aabb(aabb: TensorType[2, 3], volume_dims: TensorType[3]):
def from_aabb(aabb: Float[Tensor, "2 3"], volume_dims: Float[Tensor, "3"]):
"""Returns an instance of TSDF from an axis-aligned bounding box and volume dimensions.
Args:
@@ -167,11 +168,11 @@ class TSDF:
def integrate_tsdf(
self,
c2w: TensorType["batch", 4, 4],
K: TensorType["batch", 3, 3],
depth_images: TensorType["batch", 1, "height", "width"],
color_images: Optional[TensorType["batch", 3, "height", "width"]] = None,
mask_images: Optional[TensorType["batch", 1, "height", "width"]] = None,
c2w: Float[Tensor, "batch 4 4"],
K: Float[Tensor, "batch 3 3"],
depth_images: Float[Tensor, "batch 1 height width"],
color_images: Optional[Float[Tensor, "batch 3 height width"]] = None,
mask_images: Optional[Bool[Tensor, "batch 1 height width"]] = None,
) -> None:
"""Integrates a batch of depth images into the TSDF.
@@ -327,11 +328,11 @@ def export_tsdf_mesh(
)
# camera extrinsics and intrinsics
c2w: TensorType["N", 3, 4] = cameras.camera_to_worlds.to(device)
c2w: Float[Tensor, "N 3 4"] = cameras.camera_to_worlds.to(device)
# make c2w homogeneous
c2w = torch.cat([c2w, torch.zeros(c2w.shape[0], 1, 4, device=device)], dim=1)
c2w[:, 3, 3] = 1
K: TensorType["N", 3, 3] = cameras.get_intrinsics_matrices().to(device)
K: Float[Tensor, "N 3 3"] = cameras.get_intrinsics_matrices().to(device)
color_images = torch.tensor(np.array(color_images), device=device).permute(0, 3, 1, 2) # shape (N, 3, H, W)
depth_images = torch.tensor(np.array(depth_images), device=device).permute(0, 3, 1, 2) # shape (N, 1, H, W)