mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-05 23:38:42 +08:00
merge
This commit is contained in:
commit
e8118f0569
57 files changed
+1222
-841
No files matched your search
+20
-13
@@ -2,37 +2,44 @@
|
||||
Input/output utils.
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
|
||||
import logging
|
||||
import os
|
||||
import pickle
|
||||
|
||||
|
||||
def load_from_json(filename: str):
|
||||
"""_summary_
|
||||
|
||||
Args:
|
||||
filename (str): _description_
|
||||
|
||||
Returns:
|
||||
_type_: _description_
|
||||
"""
|
||||
"""Load a dictionary from a JSON filename."""
|
||||
assert filename.endswith(".json")
|
||||
with open(filename, "r", encoding="UTF-8") as file:
|
||||
return json.load(file)
|
||||
|
||||
|
||||
def write_to_json(filename: str, content: dict):
|
||||
"""_summary_
|
||||
"""Write data to a JSON file.
|
||||
|
||||
Args:
|
||||
filename (str): _description_
|
||||
content (dict): _description_
|
||||
filename (str): The filename to write to.
|
||||
content (dict): The dictionary data to write.
|
||||
"""
|
||||
assert filename.endswith(".json")
|
||||
with open(filename, "w", encoding="UTF-8") as file:
|
||||
json.dump(content, file)
|
||||
|
||||
|
||||
def load_from_pkl(filename: str):
|
||||
"""Load from a pickle file."""
|
||||
assert filename.endswith(".pkl")
|
||||
with open(filename, "rb") as f:
|
||||
return pickle.load(f)
|
||||
|
||||
|
||||
def write_to_pkl(filename: str, content):
|
||||
"Write to a pickle file."
|
||||
assert filename.endswith(".pkl")
|
||||
with open(filename, "wb") as f:
|
||||
pickle.dump(content, f)
|
||||
|
||||
|
||||
def get_git_root(path, dirs=(".git",), default=None):
|
||||
"""_summary_
|
||||
"https://stackoverflow.com/questions/22081209/find-the-root-of-the-git-repository-where-the-file-lives
|
||||
|
||||
@@ -2,7 +2,13 @@
|
||||
Miscellaneous helper code.
|
||||
"""
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
from pydoc import locate
|
||||
from typing import Any, Dict
|
||||
|
||||
import torch
|
||||
from omegaconf import DictConfig
|
||||
|
||||
|
||||
class DotDict(dict):
|
||||
@@ -51,3 +57,22 @@ def get_masked_dict(d, mask):
|
||||
for key, value in d.items():
|
||||
masked_dict[key] = value[mask]
|
||||
return masked_dict
|
||||
|
||||
|
||||
def instantiate_from_dict_config(dict_config: DictConfig, **kwargs):
|
||||
"""Our version of hydra's instantiate function."""
|
||||
dict_config_kwargs = {k: v for k, v in dict_config.items() if k != "_target_"}
|
||||
uninstantiated_class = locate(dict_config._target_) # pylint: disable=protected-access
|
||||
all_kwargs = dict_config_kwargs
|
||||
all_kwargs.update(kwargs)
|
||||
instantiated_class = uninstantiated_class(**all_kwargs)
|
||||
return instantiated_class
|
||||
|
||||
|
||||
def get_hash_str_from_dict(dictionary: Dict[str, Any]) -> str:
|
||||
"""MD5 hash of a dictionary. Based on
|
||||
https://www.doc.ic.ac.uk/~nuric/coding/how-to-hash-a-dictionary-in-python.html"""
|
||||
dhash = hashlib.md5()
|
||||
encoded = json.dumps(dictionary, sort_keys=True).encode()
|
||||
dhash.update(encoded)
|
||||
return dhash.hexdigest()
|
||||
@@ -52,6 +52,7 @@ def apply_depth_colormap(
|
||||
|
||||
depth = (depth - near_plane) / (far_plane - near_plane + 1e-10)
|
||||
depth = torch.clip(depth, 0, 1)
|
||||
# depth = torch.nan_to_num(depth, nan=0.0) # TODO(ethan): remove this
|
||||
|
||||
colored_image = apply_colormap(depth, cmap=cmap)
|
||||
|
||||
|
||||
Reference in new issue
Block a user