a 6dY @s`ddlZddlZddlmZddlmZddlZddlZddlZddl Z dddZ d ddZ dS) N) main_processTc Cst}tj|rtr,|d|dtj|dd}|d}|j j ||d|durh| |d|dur~| |d |durd |vr| |d ~~tr|d |d|dur|dur|d |dntrt d |d||||fS)zC Load the check point for resuming training or finetuning. zLoading weight ''cpu) map_locationmodel_state_dict)strictN optimizer schedulerscalerzSuccessfully loaded weight: 'zResume training from: 'zNo weight found at ') logging getLoggerospathisfilerinfotorchloadmoduleload_state_dict RuntimeError) Z load_pathmodelrr strict_match loss_scalerloggerZ checkpointZckpt_state_dictrDC:\Users\JUGG\Documents\GitHub\Metric3DPrivate\mono\utils\running.py load_ckpt s, rc Cst}d|jjvr|jj}n(d|jjvr4|jj}nt|jjdt|j | d|jvrh|jjn|jj| d} |dur| t| dt j |jd} t j| d d t j | d |} t| d } t| | t| d kr| t | d|d| dS)z2 Save the model, optimizer, lr scheduler. ZIterBasedRunnerZEpochBasedRunnerz is not supported max_iters)rrmax_iterr N)r ckptT)exist_okz step%08d.pthz /step*.pthrz Save model: )r r runnertyperZ max_epochs TypeErrordictr state_dictupdater rjoinZwork_dirmakedirsglobrsavelensortremovepopr) cfgrrr Z curr_iterZ curr_epochrrrrZckpt_dirZ save_nameZ saved_ckptsrrr save_ckpt)s0     r1)NNTN)rNN) r rtorch.nnnnmono.utils.commrcopyinspectr r*rr1rrrrs