@tensorleap_custom_visualizer
code_loader.inner_leap_binder.leapbinder_decorators.tensorleap_preprocess.tensorleap_custom_visualizer
The tensorleap_custom_visualizer
decorates a Visualizer Function.
@tensorleap_custom_visualizer(name='image_visualizer',
visualizer_type=LeapDataType.Image,
heatmap_function=None)
def image_visualizer(image: np.ndarray) -> LeapImage:
pass
name
(str) with the given name of the visualization, e.g. image_visualzier.
visualizer_type
(LeapDataType) This property sets the type of the data to be visualized by the visualizer.
heatmap_function
(optional)
Callable[[npt.NDArray[np.float32]], npt.NDArray[np.float32]] This parameter points to a function that modifies the heatmap data before visualization.
Visualizer inputs:
np.ndarray tensors with a batch dimension. This batch would always be 1.
Visualizers outputs:
One of the visualizer objects contraining a squeezed (no-batch) object.
Examples
Basic Usage
import numpy as np
from code_loader.visualizers.default_visualizers import LeapImage
from code_loader import leap_binder
from code_loader.contract.enums import LeapDataType
...
@tensorleap_custom_visualizer(name='image_visualizer', visualizer_type=LeapDataType.Image)
def image_visualizer(image: np.ndarray) -> LeapImage:
image = image / image.max()
image = image.squeeze(0)
return LeapImage(image)
The decoder_classes pages contain additional, decoder specific, examples. Moreover, full script usage can be found in Integration Script.
Resize Image and Heatmap
When changing the original data shape in the visualizer function, we need to reshape the heatmap data that is projected. heatmap_visualizer
points to a function that modifies the heatmap data respectively. Consider the following example:
from code_loader.contract.visualizer_classes import LeapImage
import numpy.typing as npt
def resized_image_visualizer_heatmap(data: npt.NDArray[np.float32]) -> npt.NDArray[np.float32]:
# data is the heatmap with original size (origin_W, origin_H)
return np.resize(data, (256, 512)) # we reshape to the resized shape
@tensorleap_custom_visualizer(name='image_visualizer',
visualizer_type=LeapDataType.Image,
heatmap_function=resized_image_visualizer_heatmap)
def resized_image_visualizer(data: npt.NDArray[np.float32]) -> LeapImage:
return LeapImage(np.resize(data, (256, 512, 3)))
Guides
Full examples can be found in the Dataset Integration section of the following guides:
Last updated
Was this helpful?