reduced mem on train; figuring out memory leak on visualizer

This commit is contained in:
evonneng committed 2022-09-13 03:22:07 +00:00
1 parent 416669d808
commit 139da13be8
12 files changed
+22 -13

No files matched your search

+2
View File
@@ -206,6 +206,8 @@ class DataParserConfig(InstantiateConfig):
_target: Type = DataParser _target: Type = DataParser
"""_target: target class to instantiate""" """_target: target class to instantiate"""
image_to_gpu: bool = False
"""whether to process images on gpu (else cpu)"""
@dataclass @dataclass
+2
View File
@@ -251,6 +251,8 @@ class VanillaDataManager(DataManager): # pylint: disable=abstract-method
self.train_input_dataset, self.train_input_dataset,
num_images_to_sample_from=self.config.train_num_images_to_sample_from, num_images_to_sample_from=self.config.train_num_images_to_sample_from,
device=self.device, device=self.device,
num_workers=self.world_size * 4,
pin_memory=True,
) )
self.iter_train_image_dataloader = iter(self.train_image_dataloader) self.iter_train_image_dataloader = iter(self.train_image_dataloader)
self.train_pixel_sampler = PixelSampler(self.config.train_num_rays_per_batch) self.train_pixel_sampler = PixelSampler(self.config.train_num_rays_per_batch)
+2 -2
View File
@@ -77,7 +77,7 @@ class CacheImageDataloader(DataLoader):
"""Returns a collated batch.""" """Returns a collated batch."""
batch_list = self._get_batch_list() batch_list = self._get_batch_list()
collated_batch = default_collate(batch_list) collated_batch = default_collate(batch_list)
collated_batch = get_dict_to_torch(collated_batch, device=self.device) collated_batch = get_dict_to_torch(collated_batch, device=self.device, exclude=["image"])
return collated_batch return collated_batch
def __iter__(self): def __iter__(self):
@@ -162,7 +162,7 @@ class EvalDataloader(DataLoader):
ray_bundle.num_rays_per_chunk = self.num_rays_per_chunk ray_bundle.num_rays_per_chunk = self.num_rays_per_chunk
ray_bundle.camera_indices = torch.Tensor([image_idx])[..., None].int() ray_bundle.camera_indices = torch.Tensor([image_idx])[..., None].int()
batch = self.input_dataset[image_idx] batch = self.input_dataset[image_idx]
batch = get_dict_to_torch(batch, device=self.device) batch = get_dict_to_torch(batch, device=self.device, exclude=["image"])
return ray_bundle, batch return ray_bundle, batch
+1 -1
View File
@@ -150,7 +150,7 @@ class NGPModel(Model):
return loss_dict return loss_dict
def log_test_image_outputs(self, image_idx, step, batch, outputs): def log_test_image_outputs(self, image_idx, step, batch, outputs):
image = batch["image"] image = batch["image"].to(outputs["rgb"].device)
rgb = outputs["rgb"] rgb = outputs["rgb"]
acc = visualization.apply_colormap(outputs["accumulation"]) acc = visualization.apply_colormap(outputs["accumulation"])
depth = visualization.apply_depth_colormap( depth = visualization.apply_depth_colormap(
+1 -1
View File
@@ -146,7 +146,7 @@ class MipNerfModel(Model):
return loss_dict return loss_dict
def log_test_image_outputs(self, image_idx, step, batch, outputs): def log_test_image_outputs(self, image_idx, step, batch, outputs):
image = batch["image"] image = batch["image"].to(outputs["rgb_coarse"].device)
rgb_coarse = outputs["rgb_coarse"] rgb_coarse = outputs["rgb_coarse"]
rgb_fine = outputs["rgb_fine"] rgb_fine = outputs["rgb_fine"]
acc_coarse = visualization.apply_colormap(outputs["accumulation_coarse"]) acc_coarse = visualization.apply_colormap(outputs["accumulation_coarse"])
+1 -1
View File
@@ -161,7 +161,7 @@ class MipNerf360Model(Model):
return loss_dict return loss_dict
def log_test_image_outputs(self, image_idx, step, batch, outputs): def log_test_image_outputs(self, image_idx, step, batch, outputs):
image = batch["image"] image = batch["image"].to(outputs["rgb_coarse"].device)
rgb_coarse = outputs["rgb_coarse"] rgb_coarse = outputs["rgb_coarse"]
rgb_fine = outputs["rgb_fine"] rgb_fine = outputs["rgb_fine"]
acc_coarse = visualization.apply_colormap(outputs["accumulation_coarse"]) acc_coarse = visualization.apply_colormap(outputs["accumulation_coarse"])
+1 -1
View File
@@ -215,7 +215,7 @@ class NerfWModel(Model):
return loss_dict return loss_dict
def log_test_image_outputs(self, image_idx, step, batch, outputs): def log_test_image_outputs(self, image_idx, step, batch, outputs):
image = batch["image"] image = batch["image"].to(outputs["rgb_coarse"].device)
rgb_coarse = outputs["rgb_coarse"] rgb_coarse = outputs["rgb_coarse"]
rgb_fine = outputs["rgb_fine"] rgb_fine = outputs["rgb_fine"]
rgb_fine_static = outputs["rgb_fine_static"] rgb_fine_static = outputs["rgb_fine_static"]
+1 -1
View File
@@ -114,7 +114,7 @@ class SemanticNerfModel(NeRFModel):
return outputs return outputs
def get_loss_dict(self, outputs, batch, metrics_dict, loss_coefficients): def get_loss_dict(self, outputs, batch, metrics_dict, loss_coefficients):
image = batch["image"] image = batch["image"].to(outputs["rgb_coarse"].device)
rgb_loss_coarse = self.rgb_loss(image, outputs["rgb_coarse"]) rgb_loss_coarse = self.rgb_loss(image, outputs["rgb_coarse"])
rgb_loss_fine = self.rgb_loss(image, outputs["rgb_fine"]) rgb_loss_fine = self.rgb_loss(image, outputs["rgb_fine"])
semantic_logits = outputs["semantic_fine"] semantic_logits = outputs["semantic_fine"]
+1 -1
View File
@@ -196,7 +196,7 @@ class TensoRFModel(Model):
return loss_dict return loss_dict
def log_test_image_outputs(self, image_idx, step, batch, outputs): def log_test_image_outputs(self, image_idx, step, batch, outputs):
image = batch["image"] image = batch["image"].to(outputs["rgb"].device)
rgb = outputs["rgb"] rgb = outputs["rgb"]
acc = visualization.apply_colormap(outputs["accumulation"]) acc = visualization.apply_colormap(outputs["accumulation"])
depth = visualization.apply_depth_colormap( depth = visualization.apply_depth_colormap(
+1 -1
View File
@@ -179,7 +179,7 @@ class NeRFModel(Model):
return loss_dict return loss_dict
def log_test_image_outputs(self, image_idx, step, batch, outputs): def log_test_image_outputs(self, image_idx, step, batch, outputs):
image = batch["image"] image = batch["image"].to(outputs["rgb_coarse"].device)
rgb_coarse = outputs["rgb_coarse"] rgb_coarse = outputs["rgb_coarse"]
rgb_fine = outputs["rgb_fine"] rgb_fine = outputs["rgb_fine"]
acc_coarse = visualization.apply_colormap(outputs["accumulation_coarse"]) acc_coarse = visualization.apply_colormap(outputs["accumulation_coarse"])
+6 -3
View File
@@ -19,12 +19,12 @@ Miscellaneous helper code.
import hashlib import hashlib
import json import json
from math import floor, log from math import floor, log
from typing import Any, Callable, Dict, Union from typing import Any, Callable, Dict, List, Optional, Union
import torch import torch
def get_dict_to_torch(stuff: Any, device: Union[torch.device, str] = "cpu"): def get_dict_to_torch(stuff: Any, device: Union[torch.device, str] = "cpu", exclude: Optional[List[str]] = None):
"""Set everything in the dict to the specified torch device. """Set everything in the dict to the specified torch device.
Args: Args:
@@ -32,7 +32,10 @@ def get_dict_to_torch(stuff: Any, device: Union[torch.device, str] = "cpu"):
""" """
if isinstance(stuff, dict): if isinstance(stuff, dict):
for k, v in stuff.items(): for k, v in stuff.items():
stuff[k] = get_dict_to_torch(v, device) if exclude and k in exclude:
stuff[k] = v
else:
stuff[k] = get_dict_to_torch(v, device)
return stuff return stuff
if isinstance(stuff, torch.Tensor): if isinstance(stuff, torch.Tensor):
return stuff.to(device) return stuff.to(device)
+3 -1
View File
@@ -32,6 +32,7 @@ from nerfactory.datamanagers.datasets import InputDataset
from nerfactory.models.base import Model from nerfactory.models.base import Model
from nerfactory.utils import profiler, visualization, writer from nerfactory.utils import profiler, visualization, writer
from nerfactory.utils.decorators import check_visualizer_enabled, decorate_all from nerfactory.utils.decorators import check_visualizer_enabled, decorate_all
from nerfactory.utils.misc import get_dict_to_torch
from nerfactory.utils.writer import GLOBAL_BUFFER, EventName, TimeWriter from nerfactory.utils.writer import GLOBAL_BUFFER, EventName, TimeWriter
from nerfactory.viewer.server.subprocess import run_viewer_bridge_server_as_subprocess from nerfactory.viewer.server.subprocess import run_viewer_bridge_server_as_subprocess
from nerfactory.viewer.server.utils import get_intrinsics_matrix_and_camera_to_world_h from nerfactory.viewer.server.utils import get_intrinsics_matrix_and_camera_to_world_h
@@ -415,7 +416,8 @@ class VisualizerState:
colormap_options.extend(["depth"]) colormap_options.extend(["depth"])
self.output_type_changed = False self.output_type_changed = False
self.vis["renderingState/colormap_choice"].write(self.prev_colormap_type) self.vis["renderingState/colormap_choice"].write(self.prev_colormap_type)
self.vis["renderingState/colormap_options"].write(colormap_options) self.vis["renderingState/colormap_options"].write(colormap_options)
outputs = get_dict_to_torch(outputs)
selected_output = (self._apply_colormap(outputs, stuff_colors) * 255).type(torch.uint8) selected_output = (self._apply_colormap(outputs, stuff_colors) * 255).type(torch.uint8)
image = selected_output.cpu().numpy() image = selected_output.cpu().numpy()
self.vis.set_image(image) self.vis.set_image(image)