Reduce memory usage of nerfacto model (#766)

* Reduce memory usage of nerfacto model

* Tweak config
This commit is contained in:
Matthew Tancik authored and GitHub committed 2022-10-12 18:01:58 -07:00
1 parent f273d3d9cb
commit d24d82d261
3 files changed
+9 -6

No files matched your search

+2 -2
View File
@@ -61,7 +61,7 @@ method_configs["nerfacto"] = Config(
mode="SO3xR3", optimizer=AdamOptimizerConfig(lr=6e-4, eps=1e-8, weight_decay=1e-3) mode="SO3xR3", optimizer=AdamOptimizerConfig(lr=6e-4, eps=1e-8, weight_decay=1e-3)
), ),
), ),
model=NerfactoModelConfig(eval_num_rays_per_chunk=1 << 14), model=NerfactoModelConfig(eval_num_rays_per_chunk=1 << 15),
), ),
optimizers={ optimizers={
"proposal_networks": { "proposal_networks": {
@@ -73,7 +73,7 @@ method_configs["nerfacto"] = Config(
"scheduler": None, "scheduler": None,
}, },
}, },
viewer=ViewerConfig(num_rays_per_chunk=1 << 14), viewer=ViewerConfig(num_rays_per_chunk=1 << 15),
vis="viewer", vis="viewer",
) )
+5
View File
@@ -200,6 +200,9 @@ class NerfactoModel(Model):
accumulation = self.renderer_accumulation(weights=weights) accumulation = self.renderer_accumulation(weights=weights)
outputs = {"rgb": rgb, "accumulation": accumulation, "depth": depth} outputs = {"rgb": rgb, "accumulation": accumulation, "depth": depth}
# These use a lot of GPU memory, so we avoid storing them for eval.
if self.training:
outputs["weights_list"] = weights_list outputs["weights_list"] = weights_list
outputs["ray_samples_list"] = ray_samples_list outputs["ray_samples_list"] = ray_samples_list
@@ -212,6 +215,7 @@ class NerfactoModel(Model):
metrics_dict = {} metrics_dict = {}
image = batch["image"].to(self.device) image = batch["image"].to(self.device)
metrics_dict["psnr"] = self.psnr(outputs["rgb"], image) metrics_dict["psnr"] = self.psnr(outputs["rgb"], image)
if self.training:
metrics_dict["distortion"] = distortion_loss(outputs["weights_list"], outputs["ray_samples_list"]) metrics_dict["distortion"] = distortion_loss(outputs["weights_list"], outputs["ray_samples_list"])
return metrics_dict return metrics_dict
@@ -219,6 +223,7 @@ class NerfactoModel(Model):
loss_dict = {} loss_dict = {}
image = batch["image"].to(self.device) image = batch["image"].to(self.device)
loss_dict["rgb_loss"] = self.rgb_loss(image, outputs["rgb"]) loss_dict["rgb_loss"] = self.rgb_loss(image, outputs["rgb"])
if self.training:
loss_dict["interlevel_loss"] = self.config.interlevel_loss_mult * interlevel_loss( loss_dict["interlevel_loss"] = self.config.interlevel_loss_mult * interlevel_loss(
outputs["weights_list"], outputs["ray_samples_list"] outputs["weights_list"], outputs["ray_samples_list"]
) )
+2 -4
View File
@@ -639,7 +639,6 @@ class ViewerState:
check_thread = CheckThread(state=self) check_thread = CheckThread(state=self)
render_thread = RenderThread(state=self, graph=graph, camera_ray_bundle=camera_ray_bundle) render_thread = RenderThread(state=self, graph=graph, camera_ray_bundle=camera_ray_bundle)
oom = False
with TimeWriter(None, None, write=False) as vis_t: with TimeWriter(None, None, write=False) as vis_t:
check_thread.start() check_thread.start()
render_thread.start() render_thread.start()
@@ -647,14 +646,13 @@ class ViewerState:
render_thread.join() render_thread.join()
check_thread.join() check_thread.join()
except IOChangeException: except IOChangeException:
pass del camera_ray_bundle
torch.cuda.empty_cache()
except RuntimeError as e: except RuntimeError as e:
oom = True
self.vis["renderingState/log_errors"].write( self.vis["renderingState/log_errors"].write(
"Error: GPU out of memory. Reduce resolution to prevent viewer from crashing." "Error: GPU out of memory. Reduce resolution to prevent viewer from crashing."
) )
print(f"Error: {e}") print(f"Error: {e}")
if oom:
del camera_ray_bundle del camera_ray_bundle
torch.cuda.empty_cache() torch.cuda.empty_cache()
time.sleep(0.5) # sleep to allow buffer to reset time.sleep(0.5) # sleep to allow buffer to reset