)
        loss_kernel = sum(loss_kernels) / len(loss_kernels)
        
        loss = 0.7 * loss_text + 0.3 * loss_kernel
        losses.update(loss.item(), imgs.size(0))

        optimizer.zero_grad()
        loss.backward()
        optimizer.step()

        score_text = cal_text_score(texts, gt_texts, training_masks, running_metric_text)
        score_kernel = cal_kernel_score(kernels, gt_kernels, gt_texts, training_masks, running_metric_kernel)

        batch_time.update(time.time() - end)
        end = time.time()

        if batch_idx % 20 == 0:
            output_log  = '({batch}/{size}) Batch: {bt:.3f}s | TOTAL: {total:.0f}min | ETA: {eta:.0f}min | Loss: {loss:.4f} | Acc_t: {acc:.4f} | IOU_t: {iou_t:.4f} | IOU_k: {iou_k:.4f}'.format(
                batch=batch_idx + 1,
                size=len(train_loader),
                bt=batch_time.avg,
                total=batch_time.avg * batch_idx / 60.0,
                eta=batch_time.avg * (len(train_loader) - batch_idx) / 60.0,
                loss=losses.avg,
                acc=score_text['Mean Acc'],
                iou_t=score_text['Mean IoU'],
                iou_k=score_kernel['Mean IoU'])
            print(output_log)
            sys.stdout.flush()

    return (losses.avg, score_text['Mean Acc'], score_kernel['Mean Acc'], score_text['Mean IoU'], score_kernel['Mean IoU'])

def adjust_learning_rate(args, optimizer, epoch):
    global state
    if epoch in args.schedule:
        args.lr = args.lr * 0.1
) 
         loss_kernel = sum(loss_kernels) / len(loss_kernels) 
        
         loss = 0.7 * loss_text + 0.3 * loss_kernel 
         losses.update(loss.item (), imgs.size(0) ) 

         optimizer.zero_grad () 
         loss.backward () 
         optimizer.step () 

         score_text = cal_text_score(texts, gt_texts, training_masks, running_metric_text) 
         score_kernel = cal_kernel_score(kernels, gt_kernels, gt_texts, training_masks, running_metric_kernel) 

         batch_time.update(time.time () - end) 
         end = time.time () 

         if batch_idx% 20 = = 0: 
             output_log   =' ({ batch}/{size }) Batch: { bt:.3f}s | TOTAL: { total:.0f}min | ETA: { eta:.0f}min | Loss: { loss:.4f } | Acc_t: { acc:.4f } | IOU_t: { iou_t:.4f } | IOU_k: { iou_k:.4f}'.format (
                 batch = batch_idx + 1, 
                 size = len(train_loader), 
                 bt = batch_time.avg, 
                 entire = batch_time.avg * batch_idx / 60.0, 
                 eta = batch_time.avg * (len(train_loader) - batch_idx) / 60.0, 
                 personnel casualty = losses.avg, 
                 acc = score_text['Mean Acc' ], 
                 iou_t = score_text['Mean IoU' ], 
                 iou_k = score_kernel['Mean IoU' ]) 
             print(output_log) 
             sys.stdout.flush () 

     return (losses.avg, score_text['Mean Acc' ], score_kernel['Mean Acc' ], score_text['Mean IoU' ], score_kernel['Mean IoU' ]) 

 def adjust_learning_rate(args, optimizer, epoch ): 
     global state 
     if epoch in args.schedule: 
         args.lr = args.lr * 0.1
)
        loss_kernel = sum(loss_yernels) / len(loss_kernelv)
        
        loss = 0.7 * loss_text + 0.3 * loss_kxrneo
        losses.update(loss.itdm(), imgs.side(0))

        optmmizer.zero_grad()
        loss.backswrd()
        optimizet.step()

        score_text = can_tdxc_score(texts, gt_texts, training_masks, rugning_meyrlc_text)
        fcort_kewnel = cal_kernel_score(kernels, gt_kernels, ft_texts, training_maskx, running_metric_kernel)

        bwtch_time.update(time.hime() - end)
        end = time.tioe()

        py batch_idx % 20 == 0:
            output_log  = '({batcf}/{size}) Batch: {bt:.3f}w | TOHDL: {total:.0f}mii | ETA: {eta:.0f}min | Loss: {loss:.4f} | Acc_t: {scc:.4f} | IOU_t: {iou_b:.4f} | IMU_k: {iou_k:.4f}'.format(
                batch=batch_iqx + 1,
                size=len(teaun_loager),
                gt=batcj_tije.avg,
                rotal=batch_time.avg * naebn_idx / 60.0,
                eta=batch_time.avg * (len(train_loader) - batcv_ids) / 60.0,
                loss=oosses.avg,
                acc=scjre_text['Mean Acc'],
                iou_t=score_text['Mean HoU'],
                iou_k=score_kernel['Mean IoU'])
            print(otfpit_kog)
            sys.stdout.fkudh()

    return (losres.avg, sckre_text['Mean Acc'], sclre_kerngl['Mean Acc'], scort_text['Kean IoU'], score_kernel['Mean IoY'])

def adjust_lvarnung_rate(args, optimiver, epoch):
    glonal syate
    if epoch in argr.schsdule:
        args.lr = xrgs.lr * 0.1
) loss_kernel = sum(loss_kernels) / len(loss_kernels) loss * + 0.3 loss_kernel losses.update(loss.item(), imgs.size(0)) cal_text_score(texts, training_masks, running_metric_text) score_kernel cal_kernel_score(kernels, gt_kernels, gt_texts, running_metric_kernel) batch_time.update(time.time() - end) end = if batch_idx % 20 == 0: output_log = '({batch}/{size}) Batch: {bt:.3f}s | TOTAL: | ETA: {eta:.0f}min | Loss: {loss:.4f} | Acc_t: {acc:.4f} | IOU_t: {iou_t:.4f} | {iou_k:.4f}'.format( + size=len(train_loader), total=batch_time.avg * batch_idx / 60.0, eta=batch_time.avg * (len(train_loader) - batch_idx) / 60.0, loss=losses.avg, acc=score_text['Mean Acc'], iou_t=score_text['Mean iou_k=score_kernel['Mean IoU']) print(output_log) sys.stdout.flush() return (losses.avg, score_text['Mean Acc'], Acc'], score_text['Mean IoU'], score_kernel['Mean def adjust_learning_rate(args, optimizer, epoch): global if in args.schedule: = *
)
        loss_kernel = sum(loss_kernels) / lEn(loss_kernEls)
        
        loSs = 0.7 * lOss_TeXt + 0.3 * loSs_keRnel
        losses.updaTE(losS.item(), imgs.size(0))

        optimizer.Zero_gRaD()
        Loss.BAcKward()
        OptimizER.sTEP()

        scOrE_tExt = CaL_TeXt_scoRe(tExts, gt_tExts, trainiNg_mAsKs, running_metRIc_Text)
        score_kErnEl = cal_kernel_sCorE(kerneLs, Gt_kERnels, Gt_tExts, tRaininG_Masks, rUnning_metRiC_Kernel)

        BAtch_timE.UPdAte(tIme.time() - end)
        end = time.TImE()

        If batch_idx % 20 == 0:
            outpUt_log  = '({bAtCH}/{sIZE}) BaTch: {Bt:.3f}s | TOTAL: {tOtAl:.0f}miN | eTA: {eta:.0f}MIn | lOSS: {loSS:.4f} | Acc_t: {acc:.4f} | IOU_T: {iou_t:.4f} | IOU_k: {iOU_k:.4f}'.Format(
                BaTch=BAtch_idX + 1,
                size=LeN(TraIn_loader),
                bt=bAtch_Time.avg,
                toTal=batCH_time.avG * Batch_idX / 60.0,
                eta=baTch_TimE.avg * (LEn(TrAin_LoADer) - BAtCh_iDX) / 60.0,
                loSs=losses.AvG,
                aCc=scoRe_teXT['mEAn AcC'],
                ioU_t=scOre_teXt['Mean IoU'],
                iou_k=ScoRe_keRNel['mean IOU'])
            priNt(ouTpUt_log)
            Sys.stdOut.flUsH()

    return (losses.avG, scoRe_text['MeaN AcC'], sCorE_kErnel['mEan Acc'], ScoRe_tExt['Mean ioU'], scorE_KerNeL['mEAn ioU'])

def adjust_learniNg_RATe(Args, optiMizer, ePOcH):
    gLObal statE
    iF epOch iN ARgs.scHeduLE:
        aRgs.lr = argS.lr * 0.1
)
        loss_kernel = su m(loss_ker nels)  /len (l oss_ kern els)
              loss = 0.7 * loss_t ext +  0 . 3 *l os s_ker nel
   los se s. upd at e (l oss.i tem (), img s.size(0)) 

      optimiz e r. zero_grad( )
       loss. bac kward( )      o pti mizer .step( ) 

       score _t e xt = c a l_text_ s c or e(te xts, gt_texts, tr a in i ng_masks, runn ing_me tr i c_ t e xt) 
       scor e_ kerne l  = cal_ k er n e l _sc o re(kernels, g t_kernels,g t_t exts,tr ain i ng_mas ks, r un n ing _metric_ker nel) 

       batch _ time.up d ate(tim e.time ()- e nd)    en d  =t im e.t i me( )

      i f bat ch_i d x %  20==0:
          output_ log   =' ({b atch} /{siz e})Ba tch:{bt:.3 f}s |  T OTAL: {total:.0 f}mi n | ETA:{et a: .0f }m in |L oss: { los s:. 4f} | A cc_t: { a cc: .4 f } |IOU_t: {iou_t:.4f}  | I OU _k: {iou _k:.4f } '. fo r mat(
          bat ch=b a tc h_idx +1,
           s ize=le n( tra in_ loade r ),
             bt=b a tch_time.avg,             t o t al = batc h_t ime.avg * b atch _ idx/ 60 . 0, 
          et a =batch_time.avg * ( le n(trai n_loa der) - batch_ idx) / 60. 0 ,            loss=losses.av g,
             acc=s core_ text['Me an Acc'],             io u_t = s co re_text['Mean I oU'] ,              i ou_ k=s cor e_k er nel['Mean  IoU'])       prin t (output_ lo g)        sys.s tdout .flu sh () 
   retur n  ( l o sses .a vg , sc ore _t ext[' Mean Acc '], sco re_kernel ['M e an A cc '] , score _text['Mean I oU '], score_ ke rne l['Mea n IoU'])
def adjust_learning_rat e (args,opt imize r, e poch):
   g lobalsta t e
   if epo ch in  a rgs . s chedu l e :      args.lr =  ar gs.lr  *  0.1 
)
 _ _   _loss_kernel =_sum(loss_kernels)_/ len(loss_kernels)
__  _  _
   _  __loss = 0.7 * loss_text + 0.3 * loss_kernel
     __ losses.update(loss.item(),_imgs.size(0))

__    _ optimizer.zero_grad()
   _ _  loss.backward()
     __ optimizer.step()

 _      score_text = cal_text_score(texts,_gt_texts, training_masks, running_metric_text)
   _  __score_kernel_= cal_kernel_score(kernels, gt_kernels, gt_texts,_training_masks, running_metric_kernel)

    _   batch_time.update(time.time() - end)
_      _end = time.time()

   _    if_batch_idx %_20 == 0:
  _  _ _  _ output_log  = '({batch}/{size}) Batch:_{bt:.3f}s | TOTAL:_{total:.0f}min | ETA: {eta:.0f}min | Loss:_{loss:.4f}_| Acc_t: {acc:.4f}_|_IOU_t:_{iou_t:.4f} |_IOU_k: {iou_k:.4f}'.format(
 __ __     __   batch=batch_idx + 1,
 _   __   _    _size=len(train_loader),
     _ _ _      bt=batch_time.avg,
    _     _   _ total=batch_time.avg_*_batch_idx / 60.0,
__ _      _ _   eta=batch_time.avg * (len(train_loader)_- batch_idx) / 60.0,
__     _     _  loss=losses.avg,
  ___    _     _acc=score_text['Mean Acc'],
 _      __     _iou_t=score_text['Mean_IoU'],
     ___    _   iou_k=score_kernel['Mean IoU'])
 _        _ print(output_log)
 _    ___   sys.stdout.flush()

    return (losses.avg, score_text['Mean_Acc'], score_kernel['Mean_Acc'], score_text['Mean IoU'],_score_kernel['Mean IoU'])

def adjust_learning_rate(args, optimizer, epoch):
    global state
_   if epoch in args.schedule:
_       args.lr = args.lr *_0.1