More typing fixes (#1941)

* Fix more types

* Fix tests

* Minor cleaning

* Address comments

* Resolve linting errors

* Re-ignore pymeshlab type

* Add extra assert / error message to mipnerf model
This commit is contained in:
Brent Yi authored and GitHub committed 2023-05-17 07:17:40 -07:00
1 parent 8b9574bb5a
commit 814db32ec4
53 files changed
+386 -205

No files matched your search

+1 -1
View File
@@ -74,7 +74,7 @@ class Model(nn.Module):
super().__init__()
self.config = config
self.scene_box = scene_box
self.render_aabb = None # the box that we want to render - should be a subset of scene_box
self.render_aabb: Optional[SceneBox] = None # the box that we want to render - should be a subset of scene_box
self.num_train_data = num_train_data
self.kwargs = kwargs
self.collider = None
+9 -6
View File
@@ -20,7 +20,7 @@ from __future__ import annotations
from abc import abstractmethod
from dataclasses import dataclass, field
from typing import Dict, List, Literal, Tuple, Type
from typing import Any, Dict, List, Literal, Tuple, Type
import torch
import torch.nn.functional as F
@@ -173,14 +173,15 @@ class SurfaceModel(Model):
def get_param_groups(self) -> Dict[str, List[Parameter]]:
param_groups = {}
param_groups["fields"] = list(self.field.parameters())
if self.config.background_model != "none":
param_groups["field_background"] = list(self.field_background.parameters())
else:
param_groups["field_background"] = list(self.field_background)
param_groups["field_background"] = (
[self.field_background]
if isinstance(self.field_background, Parameter)
else list(self.field_background.parameters())
)
return param_groups
@abstractmethod
def sample_and_forward_field(self, ray_bundle: RayBundle) -> Dict[str, torch.Tensor]:
def sample_and_forward_field(self, ray_bundle: RayBundle) -> Dict[str, Any]:
"""Takes in a Ray Bundle and returns a dictionary of samples and field output.
Args:
@@ -221,10 +222,12 @@ class SurfaceModel(Model):
if self.config.background_model != "none":
# sample inversely from far to 1000 and points and forward the bg model
ray_bundle.nears = ray_bundle.fars
assert ray_bundle.fars is not None
ray_bundle.fars = torch.ones_like(ray_bundle.fars) * self.config.far_plane_bg
ray_samples_bg = self.sampler_bg(ray_bundle)
# use the same background model for both density field and occupancy field
assert not isinstance(self.field_background, Parameter)
field_outputs_bg = self.field_background(ray_samples_bg)
weights_bg = ray_samples_bg.get_weights(field_outputs_bg[FieldHeadNames.DENSITY])
+9 -2
View File
@@ -36,7 +36,8 @@ from nerfstudio.model_components.renderers import (
DepthRenderer,
RGBRenderer,
)
from nerfstudio.models.base_model import Model, ModelConfig
from nerfstudio.models.base_model import Model
from nerfstudio.models.vanilla_nerf import VanillaModelConfig
from nerfstudio.utils import colormaps, colors, misc
@@ -47,12 +48,15 @@ class MipNerfModel(Model):
config: MipNerf configuration to instantiate model
"""
config: VanillaModelConfig
def __init__(
self,
config: ModelConfig,
config: VanillaModelConfig,
**kwargs,
) -> None:
self.field = None
assert config.collider_params is not None, "MipNeRF model requires bounding box collider parameters."
super().__init__(config=config, **kwargs)
def populate_modules(self):
@@ -151,6 +155,8 @@ class MipNerfModel(Model):
rgb_fine = outputs["rgb_fine"]
acc_coarse = colormaps.apply_colormap(outputs["accumulation_coarse"])
acc_fine = colormaps.apply_colormap(outputs["accumulation_fine"])
assert self.config.collider_params is not None
depth_coarse = colormaps.apply_depth_colormap(
outputs["depth_coarse"],
accumulation=outputs["accumulation_coarse"],
@@ -180,6 +186,7 @@ class MipNerfModel(Model):
fine_ssim = self.ssim(image, rgb_fine)
fine_lpips = self.lpips(image, rgb_fine)
assert isinstance(fine_ssim, torch.Tensor)
metrics_dict = {
"psnr": float(fine_psnr.item()),
"coarse_psnr": float(coarse_psnr.item()),
+1 -1
View File
@@ -271,7 +271,7 @@ class NerfactoModel(Model):
def get_outputs(self, ray_bundle: RayBundle):
ray_samples: RaySamples
ray_samples, weights_list, ray_samples_list = self.proposal_sampler(ray_bundle, density_fns=self.density_fns)
field_outputs = self.field(ray_samples, compute_normals=self.config.predict_normals)
field_outputs = self.field.forward(ray_samples, compute_normals=self.config.predict_normals)
if self.config.use_gradient_scaling:
field_outputs = scale_gradients_by_distance_squared(field_outputs, ray_samples)
+3
View File
@@ -67,6 +67,8 @@ class NeRFModel(Model):
config: Basic NeRF configuration to instantiate model
"""
config: VanillaModelConfig
def __init__(
self,
config: VanillaModelConfig,
@@ -227,6 +229,7 @@ class NeRFModel(Model):
fine_psnr = self.psnr(image, rgb_fine)
fine_ssim = self.ssim(image, rgb_fine)
fine_lpips = self.lpips(image, rgb_fine)
assert isinstance(fine_ssim, torch.Tensor)
metrics_dict = {
"psnr": float(fine_psnr.item()),