helios.core.loggers.tensorboard =============================== .. py:module:: helios.core.loggers.tensorboard Classes ------- .. autoapisummary:: helios.core.loggers.tensorboard.TensorboardWriter Module Contents --------------- .. py:class:: TensorboardWriter Bases: :py:obj:`helios.core.loggers.base.Logger` Wrapper for the Tensorboard ``SummaryWriter``. Data for the logger will be placed under ``log_root/tensorboard``. When resuming, the original run directory is restored and new data is appended to it. Requires the ``tensorboard`` package. Install it with:: pip install tensorboard .. py:method:: setup(run_name: str, log_root: pathlib.Path | None, is_resume: bool) -> None Finish configuring the ``TensorboardWriter``. In particular, this function will create the writer instance and assign it to the given path. If the path already exists, Tensorboard will automatically append to the previous run. In distributed training, the writer will only be created on rank 0. :param run_name: the name of the current run. :param log_root: root directory for logs. ``None`` disables Tensorboard. :param is_resume: ``True`` when continuing a previous run. .. py:property:: run_path :type: pathlib.Path Return the path to the current run folder. .. py:method:: add_scalar(tag: str, scalar_value: float | str | torch.Tensor, global_step: int | None = None) -> None Add scalar data to the log. :param tag: name of the scalar to plot. :param scalar_value: the scalar to plot. :param global_step: (optional) step for the given scalar. .. py:method:: add_scalars(main_tag: str, tag_scalar_dict: dict[str, float | torch.Tensor], global_step: int | None) -> None Add multiple scalars to the log. :param main_tag: the parent name for the tags. :param tag_scalar_dict: key-value pair storing tag and corresponding values. :param global_step: global step value to record. .. py:method:: add_image(tag: str, img_tensor: torch.Tensor | numpy.typing.NDArray, global_step: int | None = None, dataformats: str = 'CHW') -> None Add image data to the log. :param tag: data identifier. :param img_tensor: image data. :param global_step: (optional) global step value to record. :param dataformats: (optional) image data format specification in the form CHW, HWC, HW, WH, etc. .. py:method:: add_images(tag: str, img_tensor: torch.Tensor | numpy.typing.NDArray, global_step: int | None = None, dataformats: str = 'NCHW') -> None Add batched image data to the log. :param tag: data identifier. :param img_tensor: image data. :param global_step: (optional) global step value to record. :param dataformats: (optional) image data format specification in the form NCHW, NHWC, CHW, HWC, HW, WH, etc. .. py:method:: add_figure(tag: str, figure: matplotlib.pyplot.Figure | list[matplotlib.pyplot.Figure], global_step: int | None = None, close: bool = True) -> None Render a matplotlib figure into an image and add it to a summary. :param tag: data identifier. :param figure: figure or a list of figures. :param global_step: (optional) global step value to record. :param close: (optional) flag to automatically close the figure. .. py:method:: add_text(tag: str, text_string: str, global_step: int | None = None) -> None Add text data to the log. :param tag: data identifier. :param text_string: string to save. :param global_step: (optional) global step value to record. .. py:method:: add_graph(model: torch.nn.Module, input_to_model: torch.Tensor | list[torch.Tensor] | None = None, verbose: bool = False, use_strict_trace: bool = True) -> None Add graph data to the log. PyTorch currently supports CPU tracing only, so the model and its input(s) will be automatically moved to the CPU prior to logging. The model is copied first so the caller's model is not affected. :param model: model to draw. :param input_to_model: (optional) variable(s) to feed to the model. :param verbose: (optional) if ``True``, print graph structure in console. :param use_strict_trace: (optional) if ``True``, pass keyword argument ``strict`` to ``torch.jit.trace``. .. py:method:: add_pr_curve(tag: str, labels: torch.Tensor | numpy.typing.NDArray, predictions: torch.Tensor | numpy.typing.NDArray, global_step: int | None = None, num_thresholds: int = 127) -> None Add a precision-recall curve to the log. :param tag: data identifier. :param labels: ground truth data. Binary label for each element. :param predictions: the probability that an element be classified as true. Value should be in [0, 1]. :param global_step: (optional) global step value to record. :param num_thresholds: (optional) number of thresholds used to draw the curve. .. py:method:: add_hparams(hparam_dict: dict[str, Any], metric_dict: dict[str, Any], hparam_domain_discrete: dict[str, list[Any]] | None = None, run_name: str | None = None, global_step: int | None = None) -> None Add a set of hyper-parameters to be compared in the log. :param hparam_dict: each key-value pair is the name of a hyper-parameter and its value. Valid types are ``bool``, ``str``, ``float``, ``int``, or ``None``. :param metric_dict: each key-value pair is the name of a metric and its value. Keys must be unique in the Tensorboard record. :param hparam_domain_discrete: (optional) dictionary containing hyper-parameter names and all the discrete values they can hold. :param run_name: (optional) name of the run, to be included as part of the log dir. :param global_step: (optional) global step value to record. .. py:method:: flush() -> None Flush any cached values to Tensorboard. .. py:method:: close() -> None Close the Tensorboard writer. .. py:method:: state_dict() -> dict[str, Any] Return a dictionary containing the writer state. The state will be saved under a key called ``"run_path"`` holding the current run folder. If Tensorboard was disabled, then ``None`` is stored instead. :returns: A dictionary with the logger state. .. py:method:: load_state_dict(state_dict: dict[str, Any]) -> None Restore the writer state from a previously saved dictionary. :param state_dict: the state dictionary returned by :py:meth:`state_dict`.