ncalab.visualization ==================== .. py:module:: ncalab.visualization Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/ncalab/visualization/animation/index /autoapi/ncalab/visualization/confusionmatrix/index /autoapi/ncalab/visualization/visualization/index Attributes ---------- .. autoapisummary:: ncalab.visualization.animator_style_dark ncalab.visualization.animator_styles Classes ------- .. autoapisummary:: ncalab.visualization.AnimatorStyle ncalab.visualization.Animator ncalab.visualization.Prediction ncalab.visualization.Visual ncalab.visualization.VisualBinaryImageClassification ncalab.visualization.VisualRGBImageClassification ncalab.visualization.VisualMultiImageClassification ncalab.visualization.VisualBinaryImageSegmentation ncalab.visualization.VisualDepthEstimation ncalab.visualization.VisualGrowing Functions --------- .. autoapisummary:: ncalab.visualization.unwrap ncalab.visualization.abbreviate_label ncalab.visualization.show_image_row Package Contents ---------------- .. py:class:: AnimatorStyle(color_background, color_overlay, color_title, color_progress, underline: bool = True, progress_h: int = 3) .. py:attribute:: color_background .. py:attribute:: color_overlay .. py:attribute:: color_title .. py:attribute:: color_progress .. py:attribute:: underline :value: True .. py:attribute:: progress_h :value: 3 .. py:method:: apply(fig, ax) .. py:data:: animator_style_dark .. py:data:: animator_styles .. py:class:: Animator(nca, seed: torch.Tensor, steps: int = 100, 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. :param nca: NCA model instance :type nca: ncalab.BasicNCAModel :param seed: Input image for the NCA model :type seed: torch.Tensor :param steps: Number of NCA prediction steps per sample, defaults to 100 :type steps: int, optional :param interval: Time of each frame (milliseconds), defaults to 100 :type interval: int, optional :param repeat: Whether to loop the animation, defaults to True :type repeat: bool, optional :param repeat_delay: Time after which the animation is repeated (milliseconds), defaults to 10000 :type repeat_delay: int, optional :param overlay: Whether to overlay output channel (segmentation mask), defaults to False :type overlay: bool, optional :param show_timestep: Whether to display timestep in caption, defaults to True :type show_timestep: bool, optional .. py:attribute:: animation_fig .. py:method:: save(path: str | pathlib.Path) Save generated figure as GIF :param path: Output path :type path: str | Path .. py:class:: Prediction(model, steps: int, output_image: torch.Tensor, head_prediction: Optional[torch.Tensor] = 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. :param model: Reference to model used for prediction. :type model: ncalab.BasicNCAModel :param steps: Number of steps taken for the prediction. :type steps: int :param output_image: Output image tensor. :type output_image: torch.Tensor .. py:attribute:: model .. py:attribute:: steps .. py:attribute:: output_image .. py:attribute:: _output_array :type: Optional[numpy.ndarray] :value: None .. py:attribute:: head_prediction :value: None .. py:attribute:: _head_prediction_array :type: Optional[numpy.ndarray] :value: None .. py:property:: image_channels :type: torch.Tensor Convenience property to access the image channels as a Tensor. :returns: BCWH Tensor :rtype: torch.Tensor .. py:property:: hidden_channels :type: torch.Tensor Convenience property to access the hidden channels as a Tensor. :returns: BCWH Tensor :rtype: torch.Tensor .. py:property:: output_channels :type: torch.Tensor Convenience property to access the output channels as a Tensor. :returns: BCWH Tensor :rtype: torch.Tensor .. py:property:: output_array :type: 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 :rtype: np.ndarray .. py:property:: image_channels_np :type: 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 :rtype: np.ndarray .. py:property:: hidden_channels_np :type: numpy.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 :rtype: np.ndarray .. py:property:: output_channels_np :type: 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 :rtype: np.ndarray .. py:property:: head_prediction_array :type: numpy.ndarray | None .. py:function:: 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. :param x: Any kind of object. :type x: Any :raises RuntimeError: If x is None. :return: Just passes through the input x if it is not None. .. py:function:: abbreviate_label(L, max_len=8) .. py:function:: 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. :param ax: Axis object. :param images: List of grayscale, RGB or RGBA images, can be CWH or WHC. :param vmin: Minimum value to clip channel values, defaults to None :param vmax: Maximum value to clip channel values, defaults to None :param cmap: matplotlib colormap to apply, defaults to None :param overlays: _description_, defaults to None :param overlay_vmin: _description_, defaults to None :param overlay_vmax: _description_, defaults to None :param overlay_cmap: _description_, defaults to None :param label: y-axis label next to first image, defaults to "" :param colorbar: Whether to display a colorbar next to the last image, defaults to False :param x_index: Whether to show the batch index below each image, defaults to False :param normalize: Whether to normalize images across batch .. py:class:: Visual Base class for tensorboard visuals. .. py:method:: show(model, image: numpy.ndarray, prediction: ncalab.prediction.Prediction, label: numpy.ndarray) -> matplotlib.figure.Figure .. py:class:: VisualBinaryImageClassification Bases: :py:obj:`Visual` Base class for tensorboard visuals. .. py:method:: show(model, image: numpy.ndarray, prediction: ncalab.prediction.Prediction, label: numpy.ndarray) -> matplotlib.figure.Figure .. py:class:: VisualRGBImageClassification Bases: :py:obj:`Visual` Base class for tensorboard visuals. .. py:method:: show(model, image: numpy.ndarray, prediction: ncalab.prediction.Prediction, label: numpy.ndarray) -> matplotlib.figure.Figure .. py:class:: VisualMultiImageClassification Bases: :py:obj:`Visual` Base class for tensorboard visuals. .. py:attribute:: new_instance .. py:class:: VisualBinaryImageSegmentation Bases: :py:obj:`Visual` Base class for tensorboard visuals. .. py:method:: show(model, image: numpy.ndarray, prediction: ncalab.prediction.Prediction, label: numpy.ndarray) -> matplotlib.figure.Figure .. py:class:: VisualDepthEstimation Bases: :py:obj:`Visual` Base class for tensorboard visuals. .. py:method:: show(model, image: numpy.ndarray, prediction: ncalab.prediction.Prediction, label: numpy.ndarray) -> matplotlib.figure.Figure .. py:class:: VisualGrowing Bases: :py:obj:`Visual` Base class for tensorboard visuals. .. py:method:: show(model, image: numpy.ndarray, prediction: ncalab.prediction.Prediction, label: numpy.ndarray) -> matplotlib.figure.Figure