ncalab.visualization
Submodules
Attributes
Classes
Responsible for rendering NCA predictions as GIFs. |
|
Stores the result of an NCA prediction, including the number of steps it took. |
|
Base class for tensorboard visuals. |
|
Base class for tensorboard visuals. |
|
Base class for tensorboard visuals. |
|
Base class for tensorboard visuals. |
|
Base class for tensorboard visuals. |
|
Base class for tensorboard visuals. |
|
Base class for tensorboard visuals. |
Functions
|
|
|
Panics if x is None, otherwise returns x. |
|
|
|
Shows a row of images next to each other. |
Package Contents
- class ncalab.visualization.AnimatorStyle(color_background, color_overlay, color_title, color_progress, underline: bool = True, progress_h: int = 3)
- color_background
- color_overlay
- color_title
- color_progress
- underline = True
- progress_h = 3
- apply(fig, ax)
- ncalab.visualization.animator_style_dark
- ncalab.visualization.animator_styles
- ncalab.visualization.draw_segmentation_overlay(image, mask, style)
- class ncalab.visualization.Animator(nca: ncalab.models.AbstractNCAModel, seed: torch.Tensor, steps: int | None = None, interval: int = 100, repeat: bool = True, repeat_delay: int = 10000, overlay: bool = False, show_timestep: bool = True, hidden: bool = False, show_input: bool = False, style: str | AnimatorStyle = 'dark')
Responsible for rendering NCA predictions as GIFs.
- Parameters:
nca (ncalab.AbstractNCAModel) – NCA model instance
seed (torch.Tensor) – Input image for the NCA model
steps (int, optional) – Number of NCA prediction steps per sample, defaults to 100
interval (int, optional) – Time of each frame (milliseconds), defaults to 100
repeat (bool, optional) – Whether to loop the animation, defaults to True
repeat_delay (int, optional) – Time after which the animation is repeated (milliseconds), defaults to 10000
overlay (bool, optional) – Whether to overlay output channel (segmentation mask), defaults to False
show_timestep (bool, optional) – Whether to display timestep in caption, defaults to True
- animation_fig
- save(path: str | pathlib.Path)
Save generated figure as GIF
- Parameters:
path (str | Path) – Output path
- class ncalab.visualization.Prediction(model, steps: int, output_image: torch.Tensor, logits: torch.Tensor, head_prediction: torch.Tensor | None = None)
Stores the result of an NCA prediction, including the number of steps it took.
Sequences are typically stored by BasicNCAModel’s “record” function, and are returned as a list of Prediction objects.
Constructor is typically not called explicitly. Rather, the forward pass of BasicNCAModel (and its subclasses) is responsible for filling its attributes.
- Parameters:
model (ncalab.BasicNCAModel) – Reference to model used for prediction.
steps (int) – Number of steps taken for the prediction.
output_image (torch.Tensor) – Output image tensor.
- model
- steps
- output_image
- _output_array: numpy.ndarray | None = None
- logits
- _logits_array: numpy.ndarray | None = None
- head_prediction = None
- _head_prediction_array: numpy.ndarray | None = None
- property image_channels: torch.Tensor
Convenience property to access the image channels as a Tensor.
- Returns:
BCWH Tensor
- Return type:
torch.Tensor
Convenience property to access the hidden channels as a Tensor.
- Returns:
BCWH Tensor
- Return type:
torch.Tensor
- property output_channels: torch.Tensor
Convenience property to access the output channels as a Tensor.
- Returns:
BCWH Tensor
- Return type:
torch.Tensor
- property output_array: numpy.ndarray
Convenience property to access the whole output image in the format of a numpy array. Brings the entire tensor to CPU on demand, and only at the first call.
- Returns:
Numpy array in BCWH format
- Return type:
np.ndarray
- property image_channels_np: numpy.ndarray
Convenience property to access the output image channels in the format of a numpy array. Brings the entire tensor to CPU on demand, and only at the first call.
- Returns:
Numpy array in BCWH format
- Return type:
np.ndarray
Convenience property to access the hidden image channels in the format of a numpy array. Brings the entire tensor to CPU on demand, and only at the first call.
- Returns:
Numpy array in BCWH format
- Return type:
np.ndarray
- property output_channels_np: numpy.ndarray
Convenience property to access the image’s output channels in the format of a numpy array. Brings the entire tensor to CPU on demand, and only at the first call.
- Returns:
Numpy array in BCWH format
- Return type:
np.ndarray
- property head_prediction_array: numpy.ndarray | None
- property logits_array: numpy.ndarray
- ncalab.visualization.unwrap(x: Any)
Panics if x is None, otherwise returns x.
This is a useful shorthand for cases such as
x = unwrap(some_object).do_something()in which we are 99% certain that some_object is not None and want to avoid a mypy complaint.- Parameters:
x (Any) – Any kind of object.
- Raises:
RuntimeError – If x is None.
- Returns:
Just passes through the input x if it is not None.
- ncalab.visualization.abbreviate_label(L, max_len=8)
- ncalab.visualization.show_image_row(ax, images, vmin=None, vmax=None, cmap=None, overlays=None, overlay_vmin=None, overlay_vmax=None, overlay_cmap=None, label: str = '', colorbar: bool = False, x_index: bool = False, normalize: bool = False)
Shows a row of images next to each other.
- Parameters:
ax – Axis object.
images – List of grayscale, RGB or RGBA images, can be CWH or WHC.
vmin – Minimum value to clip channel values, defaults to None
vmax – Maximum value to clip channel values, defaults to None
cmap – matplotlib colormap to apply, defaults to None
overlays – _description_, defaults to None
overlay_vmin – _description_, defaults to None
overlay_vmax – _description_, defaults to None
overlay_cmap – _description_, defaults to None
label – y-axis label next to first image, defaults to “”
colorbar – Whether to display a colorbar next to the last image, defaults to False
x_index – Whether to show the batch index below each image, defaults to False
normalize – Whether to normalize images across batch
- class ncalab.visualization.Visual
Base class for tensorboard visuals.
- show(model, image: numpy.ndarray, prediction: ncalab.prediction.Prediction, label: numpy.ndarray) matplotlib.figure.Figure
- class ncalab.visualization.VisualBinaryImageClassification
Bases:
VisualBase class for tensorboard visuals.
- show(model, image: numpy.ndarray, prediction: ncalab.prediction.Prediction, label: numpy.ndarray) matplotlib.figure.Figure
- class ncalab.visualization.VisualRGBImageClassification
Bases:
VisualBase class for tensorboard visuals.
- show(model, image: numpy.ndarray, prediction: ncalab.prediction.Prediction, label: numpy.ndarray) matplotlib.figure.Figure
- class ncalab.visualization.VisualMultiImageClassification
Bases:
VisualBase class for tensorboard visuals.
- new_instance
- class ncalab.visualization.VisualBinaryImageSegmentation
Bases:
VisualBase class for tensorboard visuals.
- show(model, image: numpy.ndarray, prediction: ncalab.prediction.Prediction, label: numpy.ndarray) matplotlib.figure.Figure
- class ncalab.visualization.VisualDepthEstimation
Bases:
VisualBase class for tensorboard visuals.
- show(model, image: numpy.ndarray, prediction: ncalab.prediction.Prediction, label: numpy.ndarray) matplotlib.figure.Figure
- class ncalab.visualization.VisualGrowing
Bases:
VisualBase class for tensorboard visuals.
- show(model, image: numpy.ndarray, prediction: ncalab.prediction.Prediction, label: numpy.ndarray) matplotlib.figure.Figure