ncalab.models.wrappers ====================== .. py:module:: ncalab.models.wrappers Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/ncalab/models/wrappers/cascadeNCA/index /autoapi/ncalab/models/wrappers/ensemble/index Classes ------- .. autoapisummary:: ncalab.models.wrappers.CascadeNCA Package Contents ---------------- .. py:class:: CascadeNCA(wrapped: ncalab.models.basicNCA.AbstractNCAModel, scales: List[int], steps: List[int], single_model: bool = True) Bases: :py:obj:`ncalab.models.basicNCA.AbstractNCAModel` Chain multiple instances of the same NCA model, operating at different image scales. The idea is to use this model as a wrapper and drop-in replacement for an existing model. For instance, if we created a model `nca = SegmentationNCA(...)` and all code to interface with it, we could instead write `cascade = CascadeNCA(SegmentationNCA(...), scales, steps)` without the need for adjusting any of the interfacing code. This is still highly experimental. In the future, we'll work on a cleaner interface for this. :param wrapped: Backbone model based on AbstractNCAModel. :type wrapped: ncalab.AbstractNCAModel :param scales: List of scales to operate at, e.g. [4, 2, 1]. :type scales: List[int] :param steps: List of number of NCA inference time steps. :type steps: List[int] :param single_model: Only train a single instance of the NCA model :type single_model: bool .. py:attribute:: loss Compute loss. Needs to be overloaded by any subclass. Please note that the returned dict needs to hold "total" key in which the total loss is stored, which is typically a weighted sum of other losses. The total loss is backpropagated, whereas the other losses are sent to tensorboard. :param image [torch.Tensor]: Input image, BCWH. :param label [torch.Tensor]: Ground truth, BCWH. :returns: Dictionary of identifiers mapped to computed losses. .. py:attribute:: finetune Prepare model for fine tuning by freezing everything except the final layer, and setting to "train" mode. :param: freeze_head .. py:attribute:: prepare_input Preprocess input. Intended to be overwritten by subclass, if preprocessing is necessary. :param x [torch.Tensor]: Input tensor to preprocess. :returns: Processed tensor. .. py:attribute:: head .. py:attribute:: metrics .. py:attribute:: wrapped .. py:attribute:: scales .. py:attribute:: steps .. py:attribute:: single_model :value: True .. py:attribute:: models :type: List[ncalab.models.basicNCA.AbstractNCAModel] .. py:method:: forward(x: torch.Tensor, *args, **kwargs) -> ncalab.prediction.Prediction :param x: Input image tensor, BCWH. :type x: torch.Tensor :param steps: Unused, as steps are defined in constructor. :type steps: torch.Tensor :return: Prediction object :rtype: Prediction .. py:method:: record(image: torch.Tensor, steps: Optional[int | Tuple[int, int]] = None) -> List[ncalab.prediction.Prediction] Records predictions for all time steps and returns the resulting sequence of predictions. Takes care of scaling the image in between steps. :param image: Input image, BCWH. :type image: torch.Tensor :returns: List of Prediction objects. :rtype: List[Prediction]