o
    i                     @  sP   d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 G dd deZ
dS )	    )annotations)Callable)IgniteMetricHandler)
DiceMetric)MetricReductionc                      s6   e Zd ZdZdejddd ddfd fddZ  ZS )MeanDicezw
    Computes Dice score metric from full size Tensor and collects average over batch, class-channels, iterations.
    TNc                 C  s   | S )N )xr   r   Z/home/dell461/cl/sdc2/last_ska_mid/HISourceFinder-master-l/src/monai/handlers/mean_dice.py<lambda>   s    zMeanDice.<lambda>Finclude_backgroundbool	reductionMetricReduction | strnum_classes
int | Noneoutput_transformr   save_detailsreturn_with_labelbool | list[str]returnNonec                   s&   t ||||d}t j|||d dS )as  

        Args:
            include_background: whether to include dice computation on the first channel of the predicted output.
                Defaults to True.
            reduction: define the mode to reduce metrics, will only execute reduction on `not-nan` values,
                available reduction modes: {``"none"``, ``"mean"``, ``"sum"``, ``"mean_batch"``, ``"sum_batch"``,
                ``"mean_channel"``, ``"sum_channel"``}, default to ``"mean"``. if "none", will not do reduction.
            num_classes: number of input channels (always including the background). When this is None,
                ``y_pred.shape[1]`` will be used. This option is useful when both ``y_pred`` and ``y`` are
                single-channel class indices and the number of classes is not automatically inferred from data.
            output_transform: callable to extract `y_pred` and `y` from `ignite.engine.state.output` then
                construct `(y_pred, y)` pair, where `y_pred` and `y` can be `batch-first` Tensors or
                lists of `channel-first` Tensors. the form of `(y_pred, y)` is required by the `update()`.
                `engine.state` and `output_transform` inherit from the ignite concept:
                https://pytorch.org/ignite/concepts.html#state, explanation and usage example are in the tutorial:
                https://github.com/Project-MONAI/tutorials/blob/master/modules/batch_output_transform.ipynb.
            save_details: whether to save metric computation details per image, for example: mean dice of every image.
                default to True, will save to `engine.state.metric_details` dict with the metric name as key.
            return_with_label: whether to return the metrics with label, only works when reduction is "mean_batch".
                If `True`, use "label_{index}" as the key corresponding to C channels; if 'include_background' is True,
                the index begins at "0", otherwise at "1". It can also take a list of label names.
                The outcome will then be returned as a dictionary.

        See also:
            :py:meth:`monai.metrics.meandice.compute_dice`
        )r   r   r   r   )	metric_fnr   r   N)r   super__init__)selfr   r   r   r   r   r   r   	__class__r   r
   r      s   $zMeanDice.__init__)r   r   r   r   r   r   r   r   r   r   r   r   r   r   )__name__
__module____qualname____doc__r   MEANr   __classcell__r   r   r   r
   r      s    r   N)
__future__r   collections.abcr   monai.handlers.ignite_metricr   monai.metricsr   monai.utilsr   r   r   r   r   r
   <module>   s   