
    /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 )PaddleBackendzBaidu 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                F   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                                        | _        |                                r|n|j        dz  }|                                 r0ddl!m"}	 | #                    |	$                    |                     dS dS )zLoad 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)
selfr   r   pdiw
model_fileparams_fileconfigmetadata_filer   s
             c/home/longshao/multi-rider-rag/.venv/lib/python3.11/site-packages/ultralytics/nn/backends/paddle.py
load_modelzPaddleBackend.load_model   s    $+u|44p9P9P9R9RpW[WbWgkpWpEvEEEFFF 	=?@@@@ 	=45555;<<<&&&&&&LL",
K88:: 	aggh//66Jqww}55t<<KKX%%\22JK 	u{ 	uz/A/A/C/C 	uH[H[H]H] 	u#$s$s$s$stttC
OOS-=-=>> 	c!!44;K\Ka`a!bbb--f55 N;;DN<Z<Z<\<\]^<_`` N;;==  hhjj6ah/I!! 	:......		- 8 899999	: 	:    imtorch.Tensorlist[np.ndarray]c                     j                             |                                                                                    t
          j                              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.
        c                h    g | ].}j                             |                                          /S  )r*   get_output_handlecopy_to_cpu).0xr5   s     r<   
<listcomp>z)PaddleBackend.forward.<locals>.<listcomp>O   s5    ]]]a0033??AA]]]r>   )
r-   copy_from_cpur   numpyastypenpfloat32r*   runr/   )r5   r?   s   ` r<   forwardzPaddleBackend.forwardD   so     	''(8(8(?(?
(K(KLLL]]]]4K\]]]]r>   N)r   r   r   r   )r?   r@   r   rA   )__name__
__module____qualname____doc__r=   rP   rD   r>   r<   r   r      sM         +: +: +: +:Z^ ^ ^ ^ ^ ^r>   r   )
__future__r   pathlibr   rK   rM   r   r2   r   r   ultralytics.utils.checksr   baser	   r   rD   r>   r<   <module>rY      s    # " " " " "            + + + + + + + + 7 7 7 7 7 7      ?^ ?^ ?^ ?^ ?^K ?^ ?^ ?^ ?^ ?^r>   