o
    yqiá  ã                   @   s@   d dl Z d dlmZ ddlmZ ddlmZ G dd„ deƒZdS )	é    N)ÚPathé   )ÚBaseTraineré   )ÚMODELSc                   @   s8   e Zd ZdZeZdefdd„Zdd„ Zde	fdd	„Z
d
S )ÚMLClsTrainerz"Image Classification Model TrainerÚsrc_label_dict_pathc                 C   s"   t | jjƒ d¡}t ||¡ dS )zzdump label dict config

        Args:
            src_label_dict_path (str): path to label dict file to be saved.
        zlabel_dict.txtN)r   Úglobal_configÚoutputÚjoinpathÚshutilÚcopyfile)Úselfr   Zdst_label_dict_path© r   úx/home/app/PaddleOCR-VL/.venv_paddleocr/lib/python3.10/site-packages/paddlex/modules/multilabel_classification/trainer.pyÚdump_label_dict   s   zMLClsTrainer.dump_label_dictc                 C   sR  | j jr| j | j j¡ | j jr| j | j j¡ | j jr$| j | j j¡ | j | j	j
d¡ | j jdur;| j | j j¡ | j jrM| j jdkrM| j | j j¡ t| j	j
ƒ d¡}| ¡ r_|  |¡ | j jdurm| j | j j¡ | j jdur{| j | j j¡ | j jdur‰| j | j j¡ | j jdur—| j | j j¡ | j	jdur§| j | j	j¡ dS dS )zupdate training configZMLClsDatasetNÚ z	label.txt)Útrain_configZlog_intervalZ
pdx_configZupdate_log_intervalZeval_intervalZupdate_eval_intervalZsave_intervalZupdate_save_intervalZupdate_datasetr	   Zdataset_dirZnum_classesZupdate_num_classesZpretrain_weight_pathZupdate_pretrained_weightsr   r   Úexistsr   Z
batch_sizeZupdate_batch_sizeZlearning_rateZupdate_learning_rateZepochs_itersZ_update_epochsZwarmup_stepsZupdate_warmup_epochsr
   Z_update_output_dir)r   Zlabel_dict_pathr   r   r   Úupdate_config$   s:   ÿÿ
ÿzMLClsTrainer.update_configÚreturnc                 C   sX   d|   ¡ i}| jjdur| jjdkr| jj|d< | j dd¡|d< | j dd¡|d< |S )	zƒget key-value arguments of model training function

        Returns:
            dict: the arguments of training function.
        ZdeviceNr   Úresume_pathZdy2stFÚampZOFF)Z
get_devicer   r   Úget)r   Z
train_argsr   r   r   Úget_train_kwargsF   s   zMLClsTrainer.get_train_kwargsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚentitiesÚstrr   r   Údictr   r   r   r   r   r      s    	"r   )r   Úpathlibr   Úbaser   Z
model_listr   r   r   r   r   r   Ú<module>   s
   