a
    d                     @   s   d dl mZmZmZmZmZ d dlmZ deeeef  eeeef  eed eed  f e	dddd	Z
eed
ddZdeed ee f ee dddZdS )    )DictLiteralSequenceTupleUnion)TensorbboxFr   segmN)predstargetsiou_typeignore_scorereturnc                    s  t |tr|f}dddtfdd|D r@td| dfdd	|D }t | tsjtd
|  t |tstd| t| t|krtdt|  dt| g |d|sdgng  D ]*tfdd| D rtd dqg |dD ].tfdd|D r td dq |D ]. t fdd| D r4td  dq4|stdd | D rtdtdd | D rtd|D ]. t fdd|D rtd  dqtdd |D rtdt|D ]j\}}|D ]Z |  d |d d krtd!  d"| d#|  d  d$|d d  d%	qq|rpd&S t| D ]\}}|D ] |  d |d d   kr|d d ksn td!  d'| d(|  d  d)|d d  d*|d d  d%qqxd&S )+z9Ensure the correct input format of `preds` and `targets`.boxesmasksr	   c                 3   s   | ]}| vV  qd S N .0tpname_mapr   g/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/torchmetrics/detection/helpers.py	<genexpr>       z#_input_validator.<locals>.<genexpr>z	IOU type z is not supportedc                    s   g | ]} | qS r   r   r   r   r   r   
<listcomp>    r   z$_input_validator.<locals>.<listcomp>z:Expected argument `preds` to be of type Sequence, but got z;Expected argument `target` to be of type Sequence, but got zHExpected argument `preds` and `target` to have the same length, but got z and labelsscoresc                 3   s   | ]} |vV  qd S r   r   r   pkr   r   r   ,   r   z.Expected all dicts in `preds` to contain the `z` keyc                 3   s   | ]} |vV  qd S r   r   r   r!   r   r   r   0   r   z/Expected all dicts in `target` to contain the `c                 3   s   | ]}t |  tuV  qd S r   typer   r   predivnr   r   r   4   r   zExpected all z  in `preds` to be of type Tensorc                 s   s   | ]}t |d  tuV  qdS )r   Nr#   r%   r   r   r   r   6   r   z3Expected all scores in `preds` to be of type Tensorc                 s   s   | ]}t |d  tuV  qdS r   Nr#   r%   r   r   r   r   8   r   z3Expected all labels in `preds` to be of type Tensorc                 3   s   | ]}t |  tuV  qd S r   r#   r   targetr'   r   r   r   ;   r   z! in `target` to be of type Tensorc                 s   s   | ]}t |d  tuV  qdS r)   r#   r*   r   r   r   r   =   r   z4Expected all labels in `target` to be of type Tensorr   zInput 'z' and labels of sample z. in targets have a different length (expected z labels, got )Nz', labels and scores of sample z2 in predictions have a different length (expected z labels and scores, got z labels and )	
isinstancestrany	Exceptionr   
ValueErrorlen	enumeratesize)r   r   r   r   Zitem_val_nameiitemr   )r(   r"   r   r   _input_validator   sp    



8r7   )r   r   c                 C   s$   |   dkr | jdkr | dS | S )zIEmpty tensors can cause problems in DDP mode, this methods corrects them.r      )ZnumelndimZ	unsqueeze)r   r   r   r   _fix_empty_tensorsS   s    
r:   )r   r   c                    sB   d t | tr| f} t fdd| D r>td  d|  | S )N)r
   r   c                 3   s   | ]}| vV  qd S r   r   r   Zallowed_iou_typesr   r   r   ^   r   z)_validate_iou_type_arg.<locals>.<genexpr>z*Expected argument `iou_type` to be one of z or a list of, but got )r-   r.   r/   r1   )r   r   r;   r   _validate_iou_type_argZ   s    
r<   )r   F)r   )typingr   r   r   r   r   Ztorchr   r.   boolr7   r:   r<   r   r   r   r   <module>   s     @