set_visualizer
code_loader.leap_binder.set_visualizer
The
leap_binder.set_visualizer
binding function points to Visualizer Function. In addition, it defines the visualizer_type
and name
for reference.code_loader.leap_binder.set_visualizer(
name=str,
function=VisualizerCallableInterface,
visualizer_type=LeapDataType,
heatmap_visualizer=Optional[Callable[[npt.NDArray[np.float32]], npt.NDArray[np.float32]]]
)
Args | Text |
---|---|
function | |
name | (str) with the given name of the input, e.g. image. |
visualizer_type | |
heatmap_visualizer | (optional) Callable[[npt.NDArray[np.float32]], npt.NDArray[np.float32]]
This parameter points to a function that modifies the heatmap data before visualization. |
import numpy as np
from code_loader.contract.visualizer_classes import LeapText
from code_loader import leap_binder
...
def text_visualizer_func(data: np.ndarray) -> LeapText:
tokenizer = leap_binder.custom_tokenizer
text = tokenizer.sequences_to_texts(data)
return LeapText(text)
leap_binder.set_visualizer(
function=text_visualizer_func,
visualizer_type=LeapText.type,
name='text_from_token'
)
The decoder_classes pages contain additional, decoder specific, examples. Moreover, full script usage can be found in Integration Script.
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
from code_loader import le
def resized_image_visualizer(data: npt.NDArray[np.float32]) -> LeapImage:
return LeapImage(np.resize(data, (256, 512, 3)))
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
leap_binder.set_visualizer(
function=resized_image_visualizer,
name='resized_image_visualizer',
visualizer_type=LeapImage.type,
heatmap_visualizer=resized_image_visualizer_heatmap
)
Full examples can be found in the Dataset Integration section of the following guides:
Last modified 2mo ago