mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-11 02:24:38 +08:00
* abstracted some test logic and actually using test images now * moved logging from trainer to graph * fixing dataset path * refactored instant ngp code to use inheritance * fixed my run_train * fixed data path * fixed data dir
40 lines
909 B
Python
40 lines
909 B
Python
"""
|
|
Miscellaneous helper code.
|
|
"""
|
|
|
|
import torch
|
|
|
|
|
|
class DotDict(dict):
|
|
"""
|
|
dot.notation access to dictionary attributes
|
|
"""
|
|
|
|
def __getattr__(self, attr):
|
|
return self[attr]
|
|
|
|
__setattr__ = dict.__setitem__
|
|
__delattr__ = dict.__delitem__
|
|
|
|
|
|
def get_dict_to_torch(stuff, device="cpu"):
|
|
"""Set everything in the dict to the specified torch device."""
|
|
if isinstance(stuff, dict):
|
|
for k, v in stuff.items():
|
|
stuff[k] = get_dict_to_torch(v, device)
|
|
return stuff
|
|
if isinstance(stuff, torch.Tensor):
|
|
return stuff.to(device)
|
|
return stuff
|
|
|
|
|
|
def get_dict_to_cpu(stuff):
|
|
"""Set everything in the dict to CPU."""
|
|
if isinstance(stuff, dict):
|
|
for k, v in stuff.items():
|
|
stuff[k] = get_dict_to_cpu(v)
|
|
return stuff
|
|
if isinstance(stuff, torch.Tensor):
|
|
return stuff.detach().cpu()
|
|
return stuff
|