o
    W+ ic
                     @   s   d dl Z d dlmZmZ d dlmZmZ d dlmZ d dl	m
Z
mZ d dlmZ d dlmZ dd	lmZ e ZG d
d deZdS )    N)ABCabstractmethod)DictUnion)Model)Config
ConfigDict)	ModelFile)
get_logger   )build_exporterc                   @   sH   e Zd ZdZdddZedeeef fddZ	e
dd	efd
dZdS )ExporterzNExporter base class to output model to onnx, torch_script, graphdef, etc.
    Nc                 C   s
   || _ d S N)model)selfr    r   e/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/modelscope/exporters/base.py__init__   s   
zExporter.__init__r   c           
   
   K   s   t |tr
t|}t|dsJ |j}ttj	
|tj}|j}t|dr*|j}|j}t|dr;t|ds;|j|_td|ji}t|drM||j ||d< z	t|||}W |S  tys }	 ztd|j d| d	|	d
}	~	ww )aX  Build the Exporter instance.

        Args:
            model: A Model instance or a model id or a model dir, the configuration.json file besides to which
            will be used to create the exporter instance.
            kwargs: Extra kwargs used to create the Exporter instance.

        Returns:
            The Exporter instance
        	model_dir	group_key
model_typetypeexportr   zThe exporting of model 'z' with task: 'z' is not supported currently.N)
isinstancestrr   Zfrom_pretrainedhasattrr   r   	from_fileospathjoinr	   ZCONFIGURATIONtaskr   r   r   r   r   updater   r   KeyError)
clsr   kwargsr   cfgZ	task_nameZ	model_cfgZ
export_cfgZexporterer   r   r   
from_model   s8   



zExporter.from_model   
output_dirc                 K   s   dS )a'  Export the model as onnx format files.

        In some cases,  several files may be generated,
        So please return a dict which contains the generated name with the file path.

        Args:
            opset: The version of the ONNX operator set to use.
            output_dir: The output dir.
            kwargs: In this default implementation,
                kwargs will be carried to generate_dummy_inputs as extra arguments (like input shape).

        Returns:
            A dict contains the model name with the model file path.
        Nr   )r   r)   Zopsetr$   r   r   r   export_onnx;   s   zExporter.export_onnxr   )r(   )__name__
__module____qualname____doc__r   classmethodr   r   r   r'   r   r*   r   r   r   r   r      s    
$r   )r   abcr   r   typingr   r   Zmodelscope.modelsr   Zmodelscope.utils.configr   r   Zmodelscope.utils.constantr	   Zmodelscope.utils.loggerr
   Zbuilderr   loggerr   r   r   r   r   <module>   s   