
    9i                     Z    S SK r S SKrS SKJr  SSKJr  SSKJr  SSKJ	r	   " S	 S
\5      r
g)    N)Path   )FLAGS_json_format_model   )BaseTrainer   )MODELSc                   <    \ rS rSrSr\rS rS rS r	S\
4S jrSrg	)
TSCLSTrainer   zTS Classification Model Trainerc                 Z   [         R                  " U R                  R                  SS9  U R	                  5         U R                  5         U R                  5       nU R                  R                  SS5      =(       d    [        nUR                  U R                  R                  SS5      US.5        U R                  b  UR                  SU R                  05        U R                  R                  " S0 UD6nUR                  S	:X  d   S
UR                   S35       eU R                  5         g)z7firstly, update and dump train config, then train modelT)exist_okexport_with_pirFuniform_output_enabled)r   r   N	benchmarkr   z Encountered an unexpected error(z) in training! )osmakedirsglobal_configoutputupdate_configdump_configget_train_kwargsgetr   updatetrain_configbenchmark_config	pdx_modeltrain
returncodemake_tar_file)self
train_argsr   train_results       i/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/paddlex/modules/ts_classification/trainer.pyr   TSCLSTrainer.train   s    	D&&--=**,
""#4e<W@W 	 	*.*;*;*?*?,d+ $3		
   ,{D,A,ABC~~++9j9##q(	-l.E.E-F G
 	( 	    c                     [        U R                  R                  5      S-  n[        R                  " US5       nUR                  U R                  R                  SS9  SSS5        g! , (       d  f       g= f)z-make tar file to package the training outputszbest_accuracy.pdparams.tarwzbest_accuracy.pdparams)arcnameN)r   r   r   tarfileopenadd)r"   tar_pathtars      r%   r!   TSCLSTrainer.make_tar_file9   sW    **1125QQ\\(C(CGGD&&--7OGP )((s   %A((
A6c                 0   U R                   R                  U R                  R                  S5        U R                  R
                  b1  U R                   R                  SU R                  R
                  05        U R                  R                  b@  U R                   R                  SU R                  R                  R                  S5      05        U R                  R                  b1  U R                   R                  SU R                  R                  05        U R                  R                  b1  U R                   R                  SU R                  R                  05        U R                  R                  b`   [        U R                  R                  5      U R                  l        U R                   R                  SU R                  R                  05        U R                  R                  b/  U R                   R                  U R                  R                  5        U R                  R                   b/  U R                   R#                  U R                  R                   5        U R                  R$                  b/  U R                   R'                  U R                  R$                  5        U R                  R(                  b/  U R                   R+                  U R                  R(                  5        U R                  R-                  S	S
5      (       a/  U R                   R/                  U R                  R0                  5        U R                  R2                  b0  U R                   R5                  U R                  R2                  5        gg! [         a     GNf = f)zupdate training configTSCLSDatasetNtime_coltarget_cols,group_idstatic_cov_colsfreqdy2stF)
pdx_configupdate_datasetr   dataset_dirr   r3   update_basic_infor4   splitr6   r7   r8   int
ValueError
batch_sizeupdate_batch_sizelearning_rateupdate_learning_rateepochs_itersupdate_epochslog_intervalupdate_log_intervalr   update_to_staticr9   r   update_save_dir)r"   s    r%   r   TSCLSTrainer.update_config?   s   &&t'9'9'E'E~V%%1OO--z4;L;L;U;U.VW((4OO-- 1 1 = = C CC HI %%1OO--z4;L;L;U;U.VW,,8OO--"D$5$5$E$EF !!-),T->->-C-C)D!!& OO--vt7H7H7M7M.NO''3OO--d.?.?.J.JK**6OO001B1B1P1PQ))5OO))$*;*;*H*HI))5OO//0A0A0N0NO  %00OO,,T->->-D-DE$$0OO++D,>,>,E,EF 1  s   8.N 
NNreturnc                     SU R                  SS90nU R                  R                  b  U R                  R                  US'   U R                  R	                  SS5      US'   U$ )zkget key-value arguments of model training function

Returns:
    dict: the arguments of training function.
devicer   )using_device_numbersave_dirampOFF)
get_devicer   r   r   r   )r"   r#   s     r%   r   TSCLSTrainer.get_train_kwargsa   sd     A FG
$$0%)%7%7%>%>Jz" --11%?
5r'   r   N)__name__
__module____qualname____firstlineno____doc__r	   entitiesr   r!   r   dictr   __static_attributes__r   r'   r%   r   r      s(    )H8Q GD$ r'   r   )r   r+   pathlibr   utils.flagsr   baser   
model_listr	   r   r   r'   r%   <module>ra      s'    
   2  T; Tr'   