Add colormaps to logs

This commit is contained in:
Matt Tancik committed 2022-05-06 18:07:12 -07:00
1 parent c164fd5207
commit cf9c557b7b
6 files changed
+39 -6

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
""" Helper functions for visualizing outputs """
import torch
from matplotlib import cm
from torchtyping import TensorType
def apply_colormap(image: TensorType[..., 1], cmap="viridis") -> TensorType[..., 3]:
"""Convert single channel to a color image.
Args:
image (TensorType[..., 1]): Single channel image.
cmap (str, optional): Colormap for image. Defaults to 'turbo'.
Returns:
TensorType[..., 3]: Colored image
"""
colormap = cm.get_cmap(cmap)
colormap = torch.tensor(colormap.colors).to(image.device)
image = (image * 255).long()
return colormap[image]
+2 -2
View File
@@ -89,13 +89,13 @@ class TensorboardWriter(Writer):
self.tb_writer = SummaryWriter(log_dir=self.save_dir)
def write_image(
self, name: str, x: TensorType["H", "W", 3], step: int, group: str = None, prefix: str = None
self, name: str, x: TensorType["H", "W", "C"], step: int, group: str = None, prefix: str = None
) -> None:
"""_summary_
Args:
name (str): data identifier
x (TensorType["H", "W", 3]): rendered image to write
x (TensorType["H", "W", "C"]): rendered image to write
"""
x = to8b(x)
tensorboard_name = get_tensorboard_name(name, group=group, prefix=prefix)