o
    0j                     @   s|   d dl mZ ddlmZ ddlmZ ddlmZmZm	Z	m
Z
mZ dddZG d	d
 d
ZG dd deZG dd deZdS )    )deepcopy   )create_predictor)PaddlePredictorOption)build_dataset_checkerbuild_evaluatorbuild_exportorbuild_trainerbuild_weight_converterNc                 O   s   t || |d|S )N)
model_name	model_dir)_ModelBasedInference)r   r   argskwargs r   N/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddlex/model.pycreate_model   s
   r   c                   @   sL   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dS )
_BaseModelc                 O      t d)Nzcheck_dataset is not supported!	Exceptionselfr   r   r   r   r   check_dataset$      z_BaseModel.check_datasetc                 O   r   )Nztrain is not supported!r   r   r   r   r   train'   r   z_BaseModel.trainc                 O   r   )Nzevaluate is not supported!r   r   r   r   r   evaluate*   r   z_BaseModel.evaluatec                 O   r   )Nzexport is not supported!r   r   r   r   r   export-   r   z_BaseModel.exportc                 O   r   )Nz&pdparams2safetensors is not supported!r   r   r   r   r   pdparams2safetensors0   r   z_BaseModel.pdparams2safetensorsc                 O   r   )Nzpredict is not supported!r   r   r   r   r   predict3   r   z_BaseModel.predictc                 O   r   )Nzset_predict is not supported!r   r   r   r   r   set_predict6   r   z_BaseModel.set_predictc                 o       | j |i |E d H  d S N)r   r   r   r   r   __call__9      z_BaseModel.__call__N)__name__
__module____qualname__r   r   r   r   r   r   r    r#   r   r   r   r   r   #   s    r   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
r   c                 O   s   t |i || _d S r"   )r   
_predictorr   r   r   r   __init__>   s   z_ModelBasedInference.__init__c                 o   r!   r"   )r(   r   r   r   r   r   A   r$   z_ModelBasedInference.predictc                 K   s   | j jdi | d S Nr   )r(   set_predictor)r   r   r   r   r   r+   D   s   z"_ModelBasedInference.set_predictorc                 C   s2   t | j|rt| j|S td| jj d| d)N'z' object has no attribute ')hasattrr(   getattrAttributeError	__class__r%   )r   namer   r   r   __getattr__G   s
   z _ModelBasedInference.__getattr__N)r%   r&   r'   r)   r   r+   r2   r   r   r   r   r   =   s
    r   c                       sV   e Zd Zd fdd	Zdd Zdd Zdd	 Zd
d Zdd Zdd Z	dd Z
  ZS )_ModelBasedConfigNc                    s   t    || _|jj| _d S r"   )superr)   _configGlobalmodel_model_name)r   configr   r   r0   r   r   r)   P   s   
z_ModelBasedConfig.__init__c                 C   s  t | jj}|dd }| jjdd }t }|d|}|d|}|d|}|d|}|d|}	|d|}
i }||urE||d< ||urM||d< ||urat|tr]t	di |n||d	< ||uri||d< |	|urq|	|d< |
|ury|
|d< t
| jf||d
|}d|v sJ ||fS )Nr   deviceengineengine_configkernel_optionuse_hpip
hpi_configgenai_configZ	pp_option)r   r;   inputr   )r   r5   ZPredictpopr6   getobject
isinstancedictr   r   r8   )r   predict_kwargsr   r;   ZUNSETr<   r=   r>   r?   r@   rA   Zcreate_predictor_kwargs	predictorr   r   r   _build_predictorU   sH   z"_ModelBasedConfig._build_predictorc                 C      t | j}| S r"   )r   r5   check)r   Zdataset_checkerr   r   r   r   ~      
z_ModelBasedConfig.check_datasetc                 C   s   t | j}|  d S r"   )r	   r5   r   )r   Ztrainerr   r   r   r      s   
z_ModelBasedConfig.trainc                 C   rK   r"   )r   r5   r   )r   Z	evaluatorr   r   r   r      rM   z_ModelBasedConfig.evaluatec                 C   rK   r"   )r   r5   r   )r   Zexportorr   r   r   r      rM   z_ModelBasedConfig.exportc                 C   rK   r"   )r
   r5   convert)r   	converterr   r   r   r      rM   z&_ModelBasedConfig.pdparams2safetensorsc                 c   s&    |   \}}|di |E d H  d S r*   )rJ   )r   rH   rI   r   r   r   r      s   z_ModelBasedConfig.predictr"   )r%   r&   r'   r)   rJ   r   r   r   r   r   r   __classcell__r   r   r:   r   r3   O   s    )r3   r"   )copyr   Z	inferencer   Z-inference.models.runners.paddle_static.configr   modulesr   r   r   r	   r
   r   r   r   r3   r   r   r   r   <module>   s   

