
    9iQ                         S SK Jr  S SKJr  S SKJr  S SKJr  S SKJ	r	  S SK
Jr  \" 5       r\R                  " \R                  S9 " S S	\5      5       rg
)    )Trainers)EpochBasedTrainer)TRAINERS)TrainerStages)	to_device)
get_logger)module_namec                   8   ^  \ rS rSrSrU 4S jrS rS rSrU =r	$ )
ANSTrainer   zg
A trainer is used for acoustic noise suppression.
Override train_loop() to use dataset just one time.
c                 &   > [         TU ]  " U0 UD6  g N)super__init__)selfargskwargs	__class__s      e/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/modelscope/trainers/audio/ans_trainer.pyr   ANSTrainer.__init__   s    $)&)    c                 v   U R                  [        R                  5        SU l        0 nU R                  R                  5         [        U5      n[        U R                  U R                  5       GH(  nU R                  [        R                  5        SU l
        U H  u  pV[        X`R                  5      nX`l        U =R                  S-  sl
        U R                  [        R                  5        U R                  " U R                  U40 UD6  U R                  [        R                   5        U ?U =R"                  S-  sl        U R                  U R$                  :  d  M    O   U R                  [        R&                  5        U =R                  S-  sl        GM+     U R                  [        R(                  5        g)z5
Update epoch by step number, based on super method.
r      N)invoke_hookr   
before_run_epochmodeltrain	enumeraterange_max_epochsbefore_train_epoch_inner_iterr   device
data_batchbefore_train_iter
train_stepafter_train_iter_iteriters_per_epochafter_train_epoch	after_run)r   data_loaderr   
enumerated_ir%   s          r   
train_loopANSTrainer.train_loop   sI    	112

{+
t{{D$4$45A]==> D!+&z;;?
",  A%   !@!@A

JA&A  !?!?@O

a
##t';';; ", ]<<=KK1KK! 6$ 	001r   c                     g r    )r   r   inputss      r   prediction_stepANSTrainer.prediction_step3   s    r   )r   r#   r%   )
__name__
__module____qualname____firstlineno____doc__r   r1   r6   __static_attributes____classcell__)r   s   @r   r   r      s    
*2: r   r   N)modelscope.metainfor   modelscope.trainersr   modelscope.trainers.builderr   modelscope.utils.constantr   modelscope.utils.data_utilsr   modelscope.utils.loggerr   loggerregister_modulespeech_frcrn_ans_cirm_16kr   r4   r   r   <module>rH      sL    ( 1 0 3 1 .	 
h&H&HI'" ' J'r   