
    9ic
                         S SK r S SKJrJr  S SKJrJr  S SKJr  S SK	J
r
Jr  S SKJr  S SKJr  SS	KJr  \" 5       r " S
 S\5      rg)    N)ABCabstractmethod)DictUnion)Model)Config
ConfigDict)	ModelFile)
get_logger   )build_exporterc                   `    \ rS rSrSrS
S jr\S\\\	4   4S j5       r
\SS\	4S jj5       rS	rg)Exporter   zNExporter base class to output model to onnx, torch_script, graphdef, etc.
    Nc                     Xl         g Nmodel)selfr   s     Y/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/modelscope/exporters/base.py__init__Exporter.__init__   s    
    r   c                    [        U[        5      (       a  [        R                  " U5      n[	        US5      (       d   eUR
                  n[        R                  " [        R                  R                  U[        R                  5      5      nUR                  n[	        US5      (       a  UR                  nUR                  n[	        US5      (       a"  [	        US5      (       d  UR                   Ul        [%        SUR"                  05      n[	        US5      (       a  UR'                  UR(                  5        XS'    [+        XuU5      nU$ ! [,         a"  n	[-        SUR"                   SU S	35      U	eS
n	A	ff = f)a   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   from_pretrainedhasattrr   r   	from_fileospathjoinr
   CONFIGURATIONtaskr   r   r   r   r	   updater   r   KeyError)
clsr   kwargsr   cfg	task_name	model_cfg
export_cfgexporteres
             r   
from_modelExporter.from_model   sE    eS!!))%0Euk****OO	GGLLI$;$;<>HH	5+&&III	9l++GIv4N4N&11IN 89
3!!cjj)#7	7%jVDH
 	  	7+INN+;;KI; W. /0567	7s   =E 
E7E22E7
output_dirc                     g)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.
N )r   r6   opsetr-   s       r   export_onnxExporter.export_onnx;   s      	r   r   r   )   )__name__
__module____qualname____firstlineno____doc__r   classmethodr   r   r!   r4   r   r:   __static_attributes__r8   r   r   r   r      sL     "uUCZ0 " "H c  r   r   )r%   abcr   r   typingr   r   modelscope.modelsr   modelscope.utils.configr   r	   modelscope.utils.constantr
   modelscope.utils.loggerr   builderr   loggerr   r8   r   r   <module>rL      s0    	 #  # 6 / . #	<s <r   