§
    l¬¸j  ã                  ór   — 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dS )
é    )Úannotations)ÚPathN)ÚARM64ÚLOGGER)Úcheck_requirementsé   )ÚBaseBackendc                  ó"   — e Zd ZdZdd„Zdd
„ZdS )Ú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.
    Úweightú
str | PathÚreturnÚNonec                óÎ  — t          | j        t          j        ¦  «        o-t          j                             ¦   «         o| j        j        dk    }t          j        d|› d�¦  «         |rt          d¦  «         n&t          rt          d¦  «         nt          d¦  «         ddl
m} t          |¦  «        }d	\  }}|                     ¦   «         rGt          |                     d
¦  «        d¦  «        }t          |                     d¦  «        d¦  «        }n"|j        dk    r|                     d¦  «        }|}|r*|r(|                     ¦   «         r|                     ¦   «         st'          d|› d�¦  «        ‚|                     t+          |¦  «        t+          |¦  «        ¦  «        }|r#|                     d| j        j        pd¬¦  «         |                     |¦  «        | _        | j                             | j                             ¦   «         d         ¦  «        | _        | j                             ¦   «         | _        |                      |                       |¦  «        ¦  «         dS )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_id)!Ú
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Úapply_metadataÚread_metadata)Úselfr   r   ÚpdiÚwÚ
model_fileÚparams_fileÚconfigs           ún/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/ultralytics/nn/backends/paddle.pyÚ
load_modelzPaddleBackend.load_model   sM  € õ ˜$œ+¥u¤|Ñ4Ô4Ðp½¼×9PÒ9PÑ9RÔ9RÐpÐW[ÔWbÔWgÐkpÒWpˆÝŒÐE˜vÐEÐEÐEÑFÔFÐFØð 	=ÝÐ?Ñ@Ô@Ð@Ð@Ýð 	=ÝÐ4Ñ5Ô5Ð5Ð5åÐ;Ñ<Ô<Ð<à&Ð&Ð&Ð&Ð&Ð&å�‰LŒLˆØ",Ñˆ
�Kà�8Š8‰:Œ:ð 	Ý˜aŸgšg hÑ/Ô/°Ñ6Ô6ˆJÝ˜qŸwšw }Ñ5Ô5°tÑ<Ô<ˆKˆKØŒX˜Ò%Ð%ØŸš \Ñ2Ô2ˆJØˆKàð 	u˜{ð 	u¨z×/AÒ/AÑ/CÔ/Cð 	uÈ×H[ÒH[ÑH]ÔH]ð 	uÝ#Ð$sÀÐ$sÐ$sÐ$sÑtÔtÐtà—’�C 
™OœO­S°Ñ-=Ô-=Ñ>Ô>ˆØð 	cØ×!Ò!¸4È4Ì;ÔK\ÐKaÐ`aÐ!ÑbÔbÐbà×-Ò-¨fÑ5Ô5ˆŒØ œN×;Ò;¸D¼N×<ZÒ<ZÑ<\Ô<\Ð]^Ô<_Ñ`Ô`ˆÔØ œN×;Ò;Ñ=Ô=ˆÔà×Ò˜D×.Ò.¨qÑ1Ô1Ñ2Ô2Ð2Ð2Ð2ó    Úimútorch.Tensorúlist[np.ndarray]c                ó  ‡ — ‰ j                              |                     ¦   «                              ¦   «                              t
          j        d¬¦  «        ¦  «         ‰ j                             ¦   «          ˆ fd„‰ j	        D ¦   «         S )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.
        F)Úcopyc                óh   •— g | ].}‰j                              |¦  «                             ¦   «         ‘Œ/S © )r)   Úget_output_handleÚcopy_to_cpu)Ú.0Úxr1   s     €r7   ú
<listcomp>z)PaddleBackend.forward.<locals>.<listcomp>J   s5   ø€ Ð]Ð]Ð]Àa�”×0Ò0°Ñ3Ô3×?Ò?ÑAÔAÐ]Ð]Ð]r9   )
r,   Úcopy_from_cpur   ÚnumpyÚastypeÚnpÚfloat32r)   Úrunr.   )r1   r:   s   ` r7   ÚforwardzPaddleBackend.forward?   su   ø€ ð 	Ô×'Ò'¨¯ª©¬¯ªÑ(8Ô(8×(?Ò(?ÅÄ
ÐQVÐ(?Ñ(WÔ(WÑXÔXÐXØŒ×ÒÑÔÐØ]Ð]Ð]Ð]È4ÔK\Ð]Ñ]Ô]Ð]r9   N)r   r   r   r   )r:   r;   r   r<   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r8   rL   r@   r9   r7   r   r      sM   € € € € € ðð ð&3ð &3ð &3ð &3ðP^ð ^ð ^ð ^ð ^ð ^r9   r   )Ú
__future__r   Úpathlibr   rG   rI   r   Úultralytics.utilsr   r   Úultralytics.utils.checksr   Úbaser	   r   r@   r9   r7   ú<module>rV      sº   ðð #Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ð Ð à Ð Ð Ð Ø €€€à +Ð +Ð +Ð +Ð +Ð +Ð +Ð +Ø 7Ð 7Ð 7Ð 7Ð 7Ð 7à Ð Ð Ð Ð Ð ð:^ð :^ð :^ð :^ð :^�Kñ :^ô :^ð :^ð :^ð :^r9   