
    9i,                         S SK Jr  S SKJr  SSKJr  SSKJr  SSKJ	r	J
r
Jr  SSKJr  SSKJr  S	S
KJr  S\SS4S jr " S S\\S9rg)    )ABC)Path   )logging)AttrDict)check_supported_deviceset_env_for_deviceupdate_device_num)FLAGS_json_format_model)AutoRegisterABCMetaClass   )build_modelconfigreturnBaseExportorc                     U R                   R                  n  [        R	                  U5      " U 5      $ ! [         a     N'f = f)zbuild model exportor

Args:
    config (AttrDict): PaddleX pipeline config, which is loaded from pipeline yaml file.

Returns:
    BaseExportor: the exportor, which is subclass of BaseExportor.
)GlobalmodelModuleNotFoundErrorr   get)r   
model_names     ]/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/paddlex/modules/base/exportor.pybuild_exportorr      sG     $$J J'//  s   
A Ac                   f   ^  \ rS rSrSrSrU 4S jrS rS\4S jr	SS\
S\4S	 jjrS
 rS rSrU =r$ )r   /   zBase Model ExportorTc                   > [         TU ]  5         UR                  U l        UR                  U l        U R                  U R
                  R                  5      nU R
                  R                  SS5      (       a  U R
                  R                  SS5      n[        U R                  R                  US9u  U l        U l        g)zzInitialize the instance.

Args:
    config (AttrDict):  PaddleX pipeline config, which is loaded from pipeline yaml file.
basic_config_pathN)config_path)super__init__r   global_configExportexport_configget_config_pathweight_pathr   r   r   
pdx_config	pdx_model)selfr   r   	__class__s      r   r    BaseExportor.__init__4   s     	#]]#]]**4+=+=+I+IJ!!"5t<<,,001DdKK*5$$++
'    c                     [        U5      R                  S-  n UR                  5       nU(       d  [        R
                  " SU SU S35        SnU$ ! [         a    Sn N6f = f)z
get config path

Args:
    weight_path (str): The path to the weight

Returns:
    config_path (str): The path to the config

zconfig.yamlFzThe config file(`z`) related to weight file(`z%`) is not exist, use default instead.N)r   parentexists	Exceptionr   warning)r(   r%   r   	is_existss       r   r$   BaseExportor.get_config_pathF   st     ;'..>	#**,I OO#K=0KK=X}~ K  	I	s   A A! A!r   c                     U R                  5         U R                  R                  " S0 U R                  5       D6nUR                  S:X  d   SUR                   S35       eg)z?execute model exporting

Returns:
    dict: the export metrics
r   z Encountered an unexpected error(z) in exporting!N )update_configr'   exportget_export_kwargs
returncode)r(   export_results     r   r6   BaseExportor.export`   si     	--I0F0F0HI$$)	-m.F.F-G H 	) r+   using_device_numberc                 J   [        U R                  R                  U R                  R                  5        [	        U R                  R                  5        U(       a   [        U R                  R                  U5      OU R                  R                  nUR                  SS5      nU$ )zget device setting from config

Args:
    using_device_number (int, optional): specify device number to use.
        Defaults to None, means that base on config setting.

Returns:
    str: device setting, such as: `gpu:0,1`, `npu:0,1`, `cpu`.
dcugpu)r   r!   devicer   r	   r
   replace)r(   r;   device_settings      r   
get_deviceBaseExportor.get_deviceo   s     	t1188$:L:L:R:RS4--445 # d00779LM##** 	 (//u=r+   c                     g)zupdate export configNr4   )r(   s    r   r5   BaseExportor.update_config   s    r+   c                     U R                   R                  SS5      =(       d    [        nU R                  R                  U R                   R
                  U R                  S5      US.$ )z0get key-value arguments of model export functionexport_with_pirFr   )r%   save_dirr?   rG   )r!   r   r   r#   r%   outputrB   )r(   rG   s     r   r7   BaseExportor.get_export_kwargs   s_     ""#4e<W@W 	  --99**11ooa(.	
 	
r+   )r#   r!   r&   r'   )N)__name__
__module____qualname____firstlineno____doc___BaseExportor__is_baser    r$   dictr6   intstrrB   r5   r7   __static_attributes____classcell__)r)   s   @r   r   r   /   sC    I
$4 c S *#

 

r+   )	metaclassN)abcr   pathlibr   utilsr   utils.configr   utils.devicer   r	   r
   utils.flagsr   
utils.miscr   r   r   r   r4   r+   r   <module>r^      sL       $ 
 3 2 $08 0 0"b
3": b
r+   