
    FPh                     F    d dl Z d dlmZ d dlmZ d dlmZ  G d de      Zy)    N)BasePredictor)Results)opsc                       e Zd ZdZd Zy)NASPredictoraY  
    Ultralytics YOLO NAS Predictor for object detection.

    This class extends the `BasePredictor` from Ultralytics engine and is responsible for post-processing the
    raw predictions generated by the YOLO NAS models. It applies operations like non-maximum suppression and
    scaling the bounding boxes to fit the original image dimensions.

    Attributes:
        args (Namespace): Namespace containing various configurations for post-processing.

    Example:
        ```python
        from ultralytics import NAS

        model = NAS('yolo_nas_s')
        predictor = model.predictor
        # Assumes that raw_preds, img, orig_imgs are available
        results = predictor.postprocess(raw_preds, img, orig_imgs)
        ```

    Note:
        Typically, this class is not instantiated directly. It is used internally within the `NAS` class.
    c           	         t        j                  |d   d         }t        j                  ||d   d   fd      j	                  ddd      }t        j
                  || j                  j                  | j                  j                  | j                  j                  | j                  j                  | j                  j                        }t        |t              st        j                  |      }g }t        |      D ]  \  }}||   }	t        j                   |j"                  dd |ddddf   |	j"                        |ddddf<   | j$                  d   |   }
|j'                  t)        |	|
| j*                  j,                  |              |S )	z>Postprocess predictions and returns a list of Results objects.r         )agnosticmax_detclassesN   )pathnamesboxes)r   	xyxy2xywhtorchcatpermutenon_max_suppressionargsconfiouagnostic_nmsr   r   
isinstancelistconvert_torch2numpy_batch	enumeratescale_boxesshapebatchappendr   modelr   )selfpreds_inimg	orig_imgsr   predsresultsipredorig_imgimg_paths              iC:\Users\daisl\Desktop\realtime-object-detection\venv\Lib\site-packages\ultralytics/models/nas/predict.pypostprocesszNASPredictor.postprocess#   sF    hqk!n-		5(1+a.126>>q!QG''(,		(,		151G1G04		0A0A04		0A0AC )T*55i@I 'GAt |H//#))AB-a!ehnnUDBQBKzz!}Q'HNN78($**BRBRZ^_`	 (
     N)__name__
__module____qualname____doc__r0    r1   r/   r   r   
   s    0r1   r   )r   ultralytics.engine.predictorr   ultralytics.engine.resultsr   ultralytics.utilsr   r   r6   r1   r/   <module>r:      s     6 . !0= 0r1   