a
    d"                     @   s*   d dl Z de je jeee jdddZdS )    NF)inputtargetnum_classes
normalizedreturnc                 C   sN  t | s(| jt jur(tdt| t |sP|jt jurPtdt|| j|jksptd| j|j| j	|j	kstd| j	|j	t
|tr|dk rtd|| jd }| ||  }||d}g }t|D ](}|| }	t j|	|d d	}
||
 qt |}||||t j}|rJt j|d
dd}||d  }|S )a	  Compute confusion matrix to evaluate the accuracy of a classification.

    Args:
        input: tensor with estimated targets returned by a
          classifier. The shape can be :math:`(B, *)` and must contain integer
          values between 0 and K-1.
        target: tensor with ground truth (correct) target
          values. The shape can be :math:`(B, *)` and must contain integer
          values between 0 and K-1, where targets are assumed to be provided as
          one-hot vectors.
        num_classes: total possible number of classes in target.
        normalized: whether to return the confusion matrix normalized.

    Returns:
        a tensor containing the confusion matrix with shape
        :math:`(B, K, K)` where K is the number of classes.

    Example:
        >>> logits = torch.tensor([[0, 1, 0]])
        >>> target = torch.tensor([[0, 1, 0]])
        >>> confusion_matrix(logits, target, num_classes=3)
        tensor([[[2., 0., 0.],
                 [0., 1., 0.],
                 [0., 0., 0.]]])
    zEInput input type is not a torch.Tensor with torch.int64 dtype. Got {}zFInput target type is not a torch.Tensor with torch.int64 dtype. Got {}z@Inputs input and target must have the same shape. Got: {} and {}z/Inputs must be in the same device. Got: {} - {}   zAThe number of classes must be an integer bigger than two. Got: {}r   )Z	minlength   T)ZdimZkeepdimgư>)torchZ	is_tensorZdtypeint64	TypeErrorformattypeshape
ValueErrorZdevice
isinstanceintviewrangeZbincountappendstacktofloat32sum)r   r   r   r   Z
batch_sizeZpre_bincountZpre_bincount_vecZconfusion_listZiter_idZpbZ	bin_countZconfusion_vecZconfusion_matZnorm_val r   h/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/kornia/metrics/confusion_matrix.pyconfusion_matrix   s8    

r   )F)r
   ZTensorr   boolr   r   r   r   r   <module>   s
    