o
    yqi                     @   s   d dl Z d dlZd dlmZ ddlmZ ddlmZmZ ddgZ	dd	d
Z
e
ZG dd deZG dd dee jdZdddZdS )    N)OrderedDict   )UnsupportedParamError   )get_registered_model_infoget_registered_suite_infoConfig
BaseConfigc              
   C   sb   zt | }W n ty } z
tt|  d|d}~ww |d }t|}|d }|| |d}|S )_create_configz  is not a registered model name.NZsuiteconfig)
model_nameconfig_path)r   KeyErrorr   reprr   )r   r   
model_infoeZ
suite_nameZ
suite_infoZ
config_clsZ
config_obj r   d/home/app/PaddleOCR-VL/.venv_paddleocr/lib/python3.10/site-packages/paddlex/repo_apis/base/config.pyr
      s   r
   c                       s   e Zd Zd ZeZd fdd	Ze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d Zdd Zdd Z  ZS )_ConfigNc                    s0   t    |  | _|d ur| |j d S d S N)super__init___DICT_TYPE__dictreset_from_dict)selfcfg	__class__r   r   r   3   s
   

z_Config.__init__c                 C   s
   t | jS )dict)r   r   r   r   r   r   r   :   s   
z_Config.dictc                 C   s$   z| j | }|W S  ty   tw r   )r   r   AttributeErrorr   keyvalr   r   r   __getattr__?   s   
z_Config.__getattr__c                 C   s   || j |< dS )set_valNr   r"   r   r   r   r&   F      z_Config.set_valc                 C   s
   | j | S r   r'   r   r#   r   r   r   __getitem__J      
z_Config.__getitem__c                 C   s   || j |< d S r   r'   r"   r   r   r   __setitem__M   s   z_Config.__setitem__c                 C   s
   || j v S r   r'   r)   r   r   r   __contains__P   r+   z_Config.__contains__c                 K   s   |   }|| dS )
new_configN)copyupdate)r   kwargsr   r   r   r   r.   S   s   z_Config.new_configc                 C   s   t | | dS )r/   r   )typer    r   r   r   r/   X   r(   z_Config.copyc                 C   s   | j | dS )popN)r   r4   r)   r   r   r   r4   \   s   z_Config.popc                 C   s   t | ddS )Nr   indent)
format_cfgr    r   r   r   __repr__`   s   z_Config.__repr__c                 C   s   | j   | j | dS )r   N)r   clearr0   r   Zdict_like_objr   r   r   r   c   s   
z_Config.reset_from_dictr   )__name__
__module____qualname____doc__r   r   r   propertyr   r%   r&   r*   r,   r-   r.   r/   r4   r8   r   __classcell__r   r   r   r   r   .   s     
r   c                       s   e Zd ZdZd# fdd	Zdd Zejdd Zejd	d
 Z	ejdd Z
ejd$ddZejdd Zejd%ddZejd&ddZdd Zdd Zd%ddZdd Zdd  Zd!d" Z  ZS )'r	   a
  
    Abstract base class of Config.

    Config provides the functionality to load, parse, or dump to a configuration
    file with a specific format. Also, it provides APIs to update configurations
    of several important hyperparameters and model components.
    Nc                    sH   t  j|d || _|du r"|du rt| j}|d }| | dS dS )a+  
        Initialize the instance.

        Args:
            model_name (str): A registered model name.
            config_path (str|None): Path of a configuration file. Default: None.
            cfg (BaseConfig|None): `BaseConfig` object to initialize from.
                Default: None.
        r2   Nr   )r   r   r   r   load)r   r   r   r   r   r   r   r   r   r   s   

zBaseConfig.__init__c                 C   s   dS )zUpdate the deviceNr   )r   Zdevicer   r   r   update_device   s    zBaseConfig.update_devicec                 C      t )z Load configurations from a file.NotImplementedErrorr   r   r   r   r   rA         zBaseConfig.loadc                 C   rC   )zDump configurations to a file.rD   rF   r   r   r   dump   rG   zBaseConfig.dumpc                 C   rC   )z.Update configurations from a dict-like object.rD   r:   r   r   r   r0      rG   zBaseConfig.updatec                 C   rC   )z!Update configurations of dataset.rD   )r   Zdataset_dirZdataset_typer   r   r   update_dataset   rG   zBaseConfig.update_datasetc                 C   rC   )zUpdate learning rate.rD   )r   Zlearning_rater   r   r   update_learning_rate   rG   zBaseConfig.update_learning_ratetrainc                 C   rC   )zf
        Update batch size.

        By default this method modifies the training batch size.
        rD   )r   Z
batch_sizemoder   r   r   update_batch_size      zBaseConfig.update_batch_sizeFc                 C   rC   )z
        Update path to pretrained weights.

        By default this method modifies the weight path for the entire model.
        rD   )r   Zweight_pathZis_backboner   r   r   update_pretrained_weights   rN   z$BaseConfig.update_pretrained_weightsc                 C   rC   )z5Get total number of epochs or iterations in training.rD   r    r   r   r   get_epochs_iters      zBaseConfig.get_epochs_itersc                 C   rC   )z#Get learning rate used in training.rD   r    r   r   r   get_learning_rate   rQ   zBaseConfig.get_learning_ratec                 C   rC   )zb
        Get batch size.

        By default this method returns the training batch size.
        rD   )r   rL   r   r   r   get_batch_size   s   zBaseConfig.get_batch_sizec                 C   rC   )z0Get total number of epochs or iterations in QAT.rD   r    r   r   r   get_qat_epochs_iters   rQ   zBaseConfig.get_qat_epochs_itersc                 C   rC   )zGet learning rate used in QAT.rD   r    r   r   r   get_qat_learning_rate   rQ   z BaseConfig.get_qat_learning_ratec                 C   s   t | | j| dS )r/   )r   r   )r3   r   r    r   r   r   r/      s   zBaseConfig.copy)NNr   )rK   )F)r;   r<   r=   r>   r   rB   abcabstractmethodrA   rH   r0   rI   rJ   rM   rO   rP   rR   rS   rT   rU   r/   r@   r   r   r   r   r	   i   s0    




)	metaclassc           	      C   s<  t jjf}ttf}g ||R }d| }t| tr| j} t| |r^tt	| 
 D ]2\}\}}|t|d 7 }t||rI|dt||d d 7 }n|t|7 }|t| d kr[|d7 }q)|S t| |rt| D ],\}}|d7 }t||r|dt||d d 7 }n|t|7 }|t| d kr|d7 }qg|S |t| 7 }|S )r7    z: 
r   r5   z- )collectionsrV   Mappinglisttuple
isinstancer   r   	enumeratesorteditemsstrr7   len)	r   r6   Z	MAP_TYPESZ	SEQ_TYPESZNESTED_TYPESsikvr   r   r   r7      s8   





r7   r   )r   )rV   collections.abcr[   r   Zutils.errorsr   registerr   r   __all__r
   r   objectr   ABCMetar	   r7   r   r   r   r   <module>   s   
;g