Skip to content

Commit

Permalink
Add shorthand for logging images to tensorboard
Browse files Browse the repository at this point in the history
Summary:
This is be convenient for the image generation use cases, so users can avoid doing this
```
writer = tb_logger.writer
if writer:
    ...
```

Reviewed By: daniellepintz

Differential Revision: D45995451

fbshipit-source-id: 7c6d0e32ddd935b1e5860c59b5a8c3596da60e84
  • Loading branch information
ananthsub authored and facebook-github-bot committed May 19, 2023
1 parent 82f6734 commit 5f235a7
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions torchtnt/utils/loggers/tensorboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,29 @@ def log_hparams(
if self._writer:
self._writer.add_hparams(hparams, metrics)

def log_image(self, *args: Any, **kwargs: Any) -> None:
"""Add image data to TensorBoard.
Args:
*args (Any): Positional arguments passed to SummaryWriter.add_image
**kwargs(Any): Keyword arguments passed to SummaryWriter.add_image
"""
writer = self._writer
if writer:
writer.add_image(*args, **kwargs)

def log_images(self, *args: Any, **kwargs: Any) -> None:
"""Add batched image data to summary.
Args:
*args (Any): Positional arguments passed to SummaryWriter.add_images
**kwargs(Any): Keyword arguments passed to SummaryWriter.add_images
"""
writer = self._writer
if writer:
writer.add_images(*args, **kwargs)

def flush(self) -> None:
"""Writes pending logs to disk."""

Expand Down

0 comments on commit 5f235a7

Please sign in to comment.