Add Comet Logging (#2431)

* initial commit

* fixed naming

* added comet_ml as depedency

* added comet to docs

* Update custom_gui.md

* Update models.md

* Update benchmarking.md

* added Comet to ReadMe

* added decorator

* fixed link and added comet examples

* fixed link and added comet example

* fixed format

* fixed type ignore error

* fixed readme typo

* fixed typo
This commit is contained in:
Sid Mehta authored and GitHub committed 2023-09-15 09:21:09 -07:00
1 parent 805e6e702d
commit 7269a7ee16
10 files changed
+57 -26

No files matched your search

+1 -1
View File
@@ -66,7 +66,7 @@ def check_eval_enabled(func: Callable) -> Callable:
def wrapper(self, *args, **kwargs):
ret = None
if self.config.is_wandb_enabled() or self.config.is_tensorboard_enabled():
if self.config.is_wandb_enabled() or self.config.is_tensorboard_enabled() or self.config.is_comet_enabled():
ret = func(self, *args, **kwargs)
return ret
+36 -6
View File
@@ -24,16 +24,16 @@ from pathlib import Path
from time import time
from typing import Any, Dict, List, Optional, Union
import comet_ml
import torch
import wandb
from jaxtyping import Float
from torch import Tensor
from torch.utils.tensorboard import SummaryWriter
from nerfstudio.configs import base_config as cfg
from nerfstudio.utils.decorators import check_main_thread, decorate_all
from nerfstudio.utils.printing import human_format
from nerfstudio.utils.rich_utils import CONSOLE
from torch import Tensor
from torch.utils.tensorboard import SummaryWriter
def to8b(x):
@@ -150,7 +150,7 @@ def put_time(name: str, duration: float, step: int, avg_over_steps: bool = True,
put_scalar(name, duration, step)
if update_eta:
## NOTE: eta should be called with avg train iteration time
# NOTE: eta should be called with avg train iteration time
remain_iter = GLOBAL_BUFFER["max_iter"] - step
remain_time = remain_iter * GLOBAL_BUFFER["events"][name]["avg"]
put_scalar(EventName.ETA, remain_time, step)
@@ -185,7 +185,7 @@ def setup_local_writer(config: cfg.LoggingConfig, max_iter: int, banner_messages
else:
CONSOLE.log("disabled local writer")
## configure all the global buffer basic information
# configure all the global buffer basic information
GLOBAL_BUFFER["max_iter"] = max_iter
GLOBAL_BUFFER["max_buffer_size"] = config.max_buffer_size
GLOBAL_BUFFER["steps_per_log"] = config.steps_per_log
@@ -203,6 +203,7 @@ def is_initialized():
def setup_event_writer(
is_wandb_enabled: bool,
is_tensorboard_enabled: bool,
is_comet_enabled: bool,
log_dir: Path,
experiment_name: str,
project_name: str = "nerfstudio-project",
@@ -214,6 +215,11 @@ def setup_event_writer(
banner_messages: list of messages to always display at bottom of screen
"""
using_event_writer = False
if is_comet_enabled:
curr_writer = CometWriter(log_dir=log_dir, experiment_name=experiment_name, project_name=project_name)
EVENT_WRITERS.append(curr_writer)
using_event_writer = True
if is_wandb_enabled:
curr_writer = WandbWriter(log_dir=log_dir, experiment_name=experiment_name, project_name=project_name)
EVENT_WRITERS.append(curr_writer)
@@ -225,7 +231,7 @@ def setup_event_writer(
if using_event_writer:
string = f"logging events to: {log_dir}"
else:
string = "Disabled tensorboard/wandb event writers"
string = "Disabled comet/tensorboard/wandb event writers"
CONSOLE.print(f"[bold yellow]{string}")
@@ -346,6 +352,30 @@ class TensorboardWriter(Writer):
self.tb_writer.add_text("config", str(config_dict))
@decorate_all([check_main_thread])
class CometWriter(Writer):
"""Comet_ML Writer Class"""
def __init__(self, log_dir: Path, experiment_name: str, project_name: str = "nerfstudio-project"):
self.experiment = comet_ml.Experiment(project_name=project_name)
if experiment_name != "unnamed":
self.experiment.set_name(experiment_name)
def write_image(self, name: str, image: Float[Tensor, "H W C"], step: int) -> None:
self.experiment.log_image(image, name, step=step)
def write_scalar(self, name: str, scalar: Union[float, torch.Tensor], step: int) -> None:
self.experiment.log_metric(name, scalar, step)
def write_config(self, name: str, config_dict: Dict[str, Any], step: int):
"""Function that writes out the config to Comet
Args:
config: config dictionary to write out
"""
self.experiment.log_parameters(config_dict, step=step)
def _cursorup(x: int):
"""utility tool to move the cursor up on the terminal