Ë
    FêñiÌ  ã                  ój   — d dl mZ d dlmZ d dlZd dlZd dlmZm	Z	 d dl
mZ ddlmZ  G d„ d	e«      Zy)
é    )Úannotations)ÚPathN)ÚARM64ÚLOGGER)Úcheck_requirementsé   )ÚBaseBackendc                  ó    — e Zd ZdZdd„Zdd„Zy)ÚPaddleBackendzòBaidu PaddlePaddle inference backend.

    Loads and runs inference with Baidu PaddlePaddle models (*_paddle_model/ directories). Supports both CPU and GPU
    execution with automatic device configuration and memory pool initialization.
    c                óà  — t        | j                  t        j                  «      xr9 t        j                  j	                  «       xr | j                  j
                  dk7  }t        j                  d|› d�«       |rt        d«       nt        rt        d«       nt        d«       ddl
m} t        |«      }d	\  }}|j                  «       r7t        |j                  d
«      d«      }t        |j                  d«      d«      }n"|j                   dk(  r|j#                  d«      }|}|r"|r |j%                  «       r|j%                  «       st'        d|› d�«      ‚|j)                  t+        |«      t+        |«      «      }|r+|j-                  d| j                  j.                  xs d¬«       |j1                  |«      | _        | j2                  j5                  | j2                  j7                  «       d   «      | _        | j2                  j;                  «       | _        |j                  «       r|n|j>                  dz  }|jA                  «       r'ddl!m"}	 | jG                  |	jI                  |«      «       yy)zÀLoad a Baidu PaddlePaddle model from a directory containing .json and .pdiparams files.

        Args:
            weight (str | Path): Path to the model directory or .pdiparams file.
        ÚcpuzLoading z for PaddlePaddle inference...zpaddlepaddle-gpu>=3.0.0,<3.3.0zpaddlepaddle==3.0.0zpaddlepaddle>=3.0.0,<3.3.0r   N)NNz*.jsonz*.pdiparamsz
.pdiparamsz
model.jsonzPaddle model not found in z/. Both .json and .pdiparams files are required.i   )Úmemory_pool_init_size_mbÚ	device_idzmetadata.yaml)ÚYAML)%Ú
isinstanceÚdeviceÚtorchÚcudaÚis_availableÚtyper   Úinfor   r   Úpaddle.inferenceÚ	inferencer   Úis_dirÚnextÚrglobÚsuffixÚ	with_nameÚis_fileÚFileNotFoundErrorÚConfigÚstrÚenable_use_gpuÚindexÚcreate_predictorÚ	predictorÚget_input_handleÚget_input_namesÚinput_handleÚget_output_namesÚoutput_namesÚparentÚexistsÚultralytics.utilsr   Úapply_metadataÚload)
ÚselfÚweightr   ÚpdiÚwÚ
model_fileÚparams_fileÚconfigÚmetadata_filer   s
             ú`/var/www/pod-logistic/pod-ai/venv/lib/python3.12/site-packages/ultralytics/nn/backends/paddle.pyÚ
load_modelzPaddleBackend.load_model   sç  € ô ˜$Ÿ+™+¤u§|¡|Ó4Òp¼¿¹×9PÑ9PÓ9RÒpÐW[×WbÑWb×WgÑWgÐkpÑWpˆÜ�‰�h˜v˜hÐ&DÐEÔFÙÜÐ?Õ@ÝÜÐ4Õ5äÐ;Ô<å&ä�‹LˆØ",Ñˆ
�Kà�8‰8Œ:Ü˜aŸg™g hÓ/°Ó6ˆJÜ˜qŸw™w }Ó5°tÓ<‰KØ�X‰X˜Ò%ØŸ™ \Ó2ˆJØˆKá™{¨z×/AÑ/AÔ/CÈ×H[ÑH[ÔH]Ü#Ð&@ÀÀÐCrÐ$sÓtÐtà—‘œC 
›O¬S°Ó-=Ó>ˆÙØ×!Ñ!¸4È4Ï;É;×K\ÑK\ÒKaÐ`aÐ!Ôbà×-Ñ-¨fÓ5ˆŒØ ŸN™N×;Ñ;¸D¿N¹N×<ZÑ<ZÓ<\Ð]^Ñ<_Ó`ˆÔØ ŸN™N×;Ñ;Ó=ˆÔð  Ÿh™hœj™¨a¯h©h¸/ÑIˆØ×ÑÔ!Ý.à×Ñ §	¡	¨-Ó 8Õ9ð "ó    c                ój  — | j                   j                  |j                  «       j                  «       j	                  t
        j                  «      «       | j                  j                  «        | j                  D �cg c]+  }| j                  j                  |«      j                  «       ‘Œ- c}S c c}w )a  Run Baidu PaddlePaddle inference.

        Args:
            im (torch.Tensor): Input image tensor in BCHW format, normalized to [0, 1].

        Returns:
            (list[np.ndarray]): Model predictions as a list of numpy arrays, one per output handle.
        )r)   Úcopy_from_cpur   ÚnumpyÚastypeÚnpÚfloat32r&   Úrunr+   Úget_output_handleÚcopy_to_cpu)r1   ÚimÚxs      r9   ÚforwardzPaddleBackend.forwardD   sv   € ð 	×Ñ×'Ñ'¨¯©«¯©Ó(8×(?Ñ(?ÄÇ
Á
Ó(KÔLØ�‰×ÑÔØKO×K\ÑK\Ö]Àa�—‘×0Ñ0°Ó3×?Ñ?ÕAÒ]Ð]ùÒ]s   Á=0B0N)r2   z
str | PathÚreturnÚNone)rE   ztorch.TensorrH   zlist[np.ndarray])Ú__name__Ú
__module__Ú__qualname__Ú__doc__r:   rG   © r;   r9   r   r      s   „ ñó+:ôZ^r;   r   )Ú
__future__r   Úpathlibr   r>   r@   r   r.   r   r   Úultralytics.utils.checksr   Úbaser	   r   rN   r;   r9   ú<module>rS      s*   ðõ #å ã Û ç +Ý 7å ô?^�Kõ ?^r;   