
    3j"                     l    S SK r  SS\ R                  S\ R                  S\S\S\ R                  4
S jjrg)	    Npredtargetnum_classes
normalizedreturnc                 2   [         R                  " U 5      (       d4  U R                  [         R                  La  [	        S[        U 5       35      e[         R                  " U5      (       d4  UR                  [         R                  La  [	        S[        U5       35      eU R                  UR                  :X  d%  [        SU R                   SUR                   35      eU R                  UR                  :X  d%  [        SU R                   SUR                   35      e[        U[        5      (       a  US:  a  [        SU 35      eU R                  S	   nXU-  -   nUR                  US
5      n/ n[        U5       H/  nXh   n	[         R                  " XS-  S9n
UR                  U
5        M1     [         R                  " U5      nUR                  XBU5      R!                  [         R"                  5      nU(       a  [         R$                  " USSS9nXS-   -  nU$ )a  Compute confusion matrix to evaluate the accuracy of a classification.

Args:
    pred: 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.]]])

zBInput pred type is not a torch.Tensor with torch.int64 dtype. Got zDInput target type is not a torch.Tensor with torch.int64 dtype. Got z6Inputs pred and target must have the same shape. Got: z and z(Inputs must be in the same device. Got: z -    z?The number of classes must be an integer bigger than two. Got: r   )	minlength   T)dimkeepdimgư>)torch	is_tensordtypeint64	TypeErrortypeshape
ValueErrordevice
isinstanceintviewrangebincountappendstacktofloat32sum)r   r   r   r   
batch_sizepre_bincountpre_bincount_vecconfusion_listiter_idpb	bin_countconfusion_vecconfusion_matnorm_vals                 Y/home/wildlama/miniconda3/lib/python3.13/site-packages/kornia/metrics/confusion_matrix.pyconfusion_matrixr-      s   : ??4  TZZu{{%B\]abf]g\hijj??6""v||5;;'F^_cdj_k^lmnn::%QRVR\R\Q]]bcicocobpqrr;;&--'CDKK=PSTZTaTaSbcddk3'';?Z[fZghiijjmJ "&(<!<L%1%6%6z2%FN$+4"'..A~"N	i( %
 #(++n"=M"/"4"4Zk"Z"]"]^c^k^k"lM!&=a!N%D9    )F)r   Tensorr   boolr-    r.   r,   <module>r2      sJ   $  TY>
,,> %>;>>LP>
\\>r.   