
    |-j,                         d dl mZ d dlmZ ddlmZ ddlmZ ddlm	Z	m
Z
mZ ddlmZ ddlmZ d	d
lmZ deddfdZ G d dee          ZdS )    )ABC)Path   )logging)AttrDict)check_supported_deviceset_env_for_deviceupdate_device_num)FLAGS_json_format_model)AutoRegisterABCMetaClass   )build_modelconfigreturnBaseExportorc                     | j         j        }	 n# t          $ r Y nw xY wt                              |          |           S )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/banglarbhumi/venv/lib/python3.11/site-packages/paddlex/modules/base/exportor.pybuild_exportorr      sR     $J   J''///s   
c                   V     e Zd ZdZdZ fdZd ZdefdZdde	de
fd	Zd
 Zd Z xZS )r   zBase Model ExportorTc                 r   t                                                       |j        | _        |j        | _        |                     | j        j                  }| j                            dd          r| j                            dd          }t          | j        j
        |          \  | _        | _        dS )zInitialize 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   zBaseExportor.__init__4   s     	#]#]**4+=+IJJ!!"5t<< 	L,001DdKKK*5$++
 +
 +
'    c                     t          |          j        dz  }	 |                                }n# t          $ r d}Y nw xY w|st	          j        d| d| d           d}|S )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#   zBaseExportor.get_config_pathF   s     ;''.>	#**,,II 	 	 	III	 	O~K~~K~~~   Ks   . ==r   c                     |                                    | j        j        di |                                 }|j        dk    sJ d|j         d            dS )zWexecute 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   r3   zBaseExportor.export`   sx     	--II0F0F0H0HII$)))m.F    *)) tr)   Nusing_device_numberc                     t          | j        j        | j        j                   t	          | j        j                   |rt          | j        j        |          n| j        j        }|                    dd          }|S )a#  get 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'   r7   device_settings      r   
get_devicezBaseExportor.get_deviceo   s     	t18$:L:RSSS4-4555 #+d079LMMM#* 	 (//u==r)   c                     dS )zupdate export configNr1   )r'   s    r   r2   zBaseExportor.update_config   s      r)   c                     | j                             dd          pt          }| j        j        | j         j        |                     d          |dS )z0get key-value arguments of model export functionexport_with_pirFr   )r$   save_dirr;   rA   )r    r   r   r"   r$   outputr>   )r'   rA   s     r   r4   zBaseExportor.get_export_kwargs   s[     ""#4e<<W@W 	  -9*1ooa((.	
 
 	
r)   )N)__name__
__module____qualname____doc___BaseExportor__is_baser   r#   dictr3   intstrr>   r2   r4   __classcell__)r(   s   @r   r   r   /   s        I
 
 
 
 
$  4     c S    *# # #

 

 

 

 

 

 

r)   )	metaclassN)abcr   pathlibr   utilsr   utils.configr   utils.devicer   r	   r
   utils.flagsr   
utils.miscr   r   r   r   r1   r)   r   <module>rU      s"                     $ $ $ $ $ $         
 3 2 2 2 2 2 2 2 2 2 2 2 $ $ $ $ $ $08 0 0 0 0 0"b
 b
 b
 b
 b
3": b
 b
 b
 b
 b
 b
r)   