o
    yqi                     @   sp   d dl mZ ddlmZmZ ddl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   )PaddlePredictorOptioncreate_predictor)build_dataset_checkerbuild_evaluatorbuild_exportorbuild_trainerNc                 O   s   t || |d|S )N)
model_name	model_dir)_ModelBasedInference)r
   r   argskwargs r   T/home/app/PaddleOCR-VL/.venv_paddleocr/lib/python3.10/site-packages/paddlex/model.pycreate_model   s
   r   c                   @   sD   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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predict is not supported!r   r   r   r   r   predict.   r   z_BaseModel.predictc                 O   r   )Nzset_predict is not supported!r   r   r   r   r   set_predict1   r   z_BaseModel.set_predictc                 o       | j |i |E d H  d S N)r   r   r   r   r   __call__4      z_BaseModel.__call__N)
__name__
__module____qualname__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__9   s   z_ModelBasedInference.__init__c                 o   r   r    )r&   r   r   r   r   r   <   r"   z_ModelBasedInference.predictc                 K   s   | j jdi | d S Nr   )r&   set_predictor)r   r   r   r   r   r)   ?   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__B   s
   z _ModelBasedInference.__getattr__N)r#   r$   r%   r'   r   r)   r0   r   r   r   r   r   8   s
    r   c                       sN   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	  Z
S )_ModelBasedConfigNc                    s   t    || _|jj| _d S r    )superr'   _configGlobalmodel_model_name)r   configr   r   r.   r   r   r'   K   s   
z_ModelBasedConfig.__init__c                 C   s   t | jj}|dd }| jjdd }t }|d|}|d|}|d|}|d|}i }	||ur>tdi ||	d< ||urG||	d< nd|	d< ||urS||	d< ||ur[||	d< t| j	f||d	|	}
d
|v smJ ||
fS )Nr   devicekernel_optionuse_hpip
hpi_configgenai_configZ	pp_optionF)r   r9   inputr   )
r   r3   ZPredictpopr4   getobjectr   r   r6   )r   predict_kwargsr   r9   ZUNSETr:   r;   r<   r=   Zcreate_predictor_kwargs	predictorr   r   r   _build_predictorP   s<   

z"_ModelBasedConfig._build_predictorc                 C      t | j}| S r    )r   r3   check)r   Zdataset_checkerr   r   r   r   s      
z_ModelBasedConfig.check_datasetc                 C   s   t | j}|  d S r    )r	   r3   r   )r   Ztrainerr   r   r   r   w   s   
z_ModelBasedConfig.trainc                 C   rE   r    )r   r3   r   )r   Z	evaluatorr   r   r   r   {   rG   z_ModelBasedConfig.evaluatec                 C   rE   r    )r   r3   r   )r   Zexportorr   r   r   r      rG   z_ModelBasedConfig.exportc                 c   s&    |   \}}|di |E d H  d S r(   )rD   )r   rB   rC   r   r   r   r      s   z_ModelBasedConfig.predictr    )r#   r$   r%   r'   rD   r   r   r   r   r   __classcell__r   r   r8   r   r1   J   s    #r1   r    )copyr   Z	inferencer   r   modulesr   r   r   r	   r   r   r   r1   r   r   r   r   <module>   s   
	