§
    l¬¸j	  ã                  ób   — d dl mZ d dlmZ d dlZd dlZd dlmZ ddl	m
Z
  G d„ de
¦  «        ZdS )	é    )Úannotations)ÚPathN)ÚLOGGERé   )ÚBaseBackendc                  ó(   — e Zd ZdZdd„Zd„ Zdd„ZdS )ÚAscendBackendzÝHuawei Ascend NPU inference backend for CANN offline models.

    Loads a compiled .om offline model and runs inference on the Ascend AI Processor through the ais_bench runtime,
    which wraps CANN's pyACL bindings.
    Úweightú
str | PathÚreturnÚNonec                óÎ  — 	 ddl m} n"# t          $ r}t          d¦  «        |‚d}~ww xY wt          j        d|› d�¦  «         t          |¦  «        }t          |                     d¦  «        d¦  «        }|€t          d|› �¦  «        ‚ |t          | j
        d	d¦  «        pdt          |¦  «        ¦  «        | _        |                      |                      |¦  «        ¦  «         dS )
ai  Load an Ascend model from a directory containing a .om file.

        Args:
            weight (str | Path): Path to the Ascend model directory containing the .om offline model.

        Raises:
            ImportError: If the ``ais_bench`` Python package is not installed.
            FileNotFoundError: If no .om file is found in the given directory.
        r   )ÚInferSessionz¦Ascend inference requires the CANN runtime and `ais_bench` Python package. See https://docs.ultralytics.com/integrations/ascend#runtime-installation for instructions.NzLoading z for Huawei Ascend inference...z*.omzNo .om file found in: Úindex)Úais_bench.infer.interfacer   ÚImportErrorr   Úinfor   ÚnextÚrglobÚFileNotFoundErrorÚgetattrÚdeviceÚstrÚmodelÚapply_metadataÚread_metadata)Úselfr
   r   ÚeÚwÚfounds         ún/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/ultralytics/nn/backends/ascend.pyÚ
load_modelzAscendBackend.load_model   s  € ð	Ø>Ð>Ð>Ð>Ð>Ð>Ð>øÝð 	ð 	ð 	Ýðnñô ð ðøøøøð	øøøõ 	ŒÐF˜vÐFÐFÐFÑGÔGÐGå�‰LŒLˆÝ�Q—W’W˜V‘_”_ dÑ+Ô+ˆØˆ=Ý#Ð$@¸QÐ$@Ð$@ÑAÔAÐAà!�\¥'¨$¬+°wÀÑ"EÔ"EÐ"JÈÍCÐPUÉJÌJÑWÔWˆŒ
à×Ò˜D×.Ò.¨uÑ5Ô5Ñ6Ô6Ð6Ð6Ð6s   ‚	 ‰
(“#£(c                óX   — t          | dd¦  «        x}r|                     ¦   «          dS dS )zGRelease the Ascend device-side resources held by the inference session.r   N)r   Úfree_resource)r   r   s     r!   Ú__del__zAscendBackend.__del__3   s=   € å˜D '¨4Ñ0Ô0Ð0ˆ5ð 	"Ø×ÒÑ!Ô!Ð!Ð!Ð!ð	"ð 	"ó    Úimútorch.Tensorúnp.ndarray | list[np.ndarray]c                óº   — | j                              |                     ¦   «                              ¦   «         g¦  «        }t	          |¦  «        dk    r|d         n|S )a  Run inference on the Ascend NPU.

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

        Returns:
            (np.ndarray | list[np.ndarray]): Model predictions as a single array or list of arrays.
        r   r   )r   ÚinferÚcpuÚnumpyÚlen)r   r'   Úys      r!   ÚforwardzAscendBackend.forward8   sJ   € ð ŒJ×Ò˜bŸfšf™hœhŸnšnÑ.Ô.Ð/Ñ0Ô0ˆÝ˜1‘v”v ’{�{ˆq�Œtˆt¨Ð)r&   N)r
   r   r   r   )r'   r(   r   r)   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r"   r%   r0   © r&   r!   r	   r	      sU   € € € € € ðð ð7ð 7ð 7ð 7ð:"ð "ð "ð

*ð 
*ð 
*ð 
*ð 
*ð 
*r&   r	   )Ú
__future__r   Úpathlibr   r-   ÚnpÚtorchÚultralytics.utilsr   Úbaser   r	   r5   r&   r!   ú<module>r<      s˜   ðð #Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ð Ð à Ð Ð Ð Ø €€€à $Ð $Ð $Ð $Ð $Ð $à Ð Ð Ð Ð Ð ð3*ð 3*ð 3*ð 3*ð 3*�Kñ 3*ô 3*ð 3*ð 3*ð 3*r&   