(self)
Load ckpt if --load option is specified
Load ckpt if --load option is specified
Load ckpt if -- load option is specified
def load_ckpt(self):
        ''' Load ckpt if --load option is specified '''
        if self.paras.load:
            # Load weights
            ckpt = torch.load(
                self.paras.load, map_location=self.device if self.mode == 'train' else 'cpu')
            self.model.load_state_dict(ckpt['model'])
            if self.emb_decoder is not None:
                self.emb_decoder.load_state_dict(ckpt['emb_decoder'])
            # if self.amp:
            #    amp.load_state_dict(ckpt['amp'])
            # Load task-dependent items
            metric = "None"
            score = 0.0
            for k, v in ckpt.items():
                if type(v) is float:
                    metric, score = k, v
            if self.mode == 'train':
                self.step = ckpt['global_step']
                self.optimizer.load_opt_state_dict(ckpt['optimizer'])
                self.verbose('Load ckpt from {}, restarting at step {} (recorded {} = {:.2f} %)'.format(
                              self.paras.load, self.step, metric, score))
            else:
                self.model.eval()
                if self.emb_decoder is not None:
                    self.emb_decoder.eval()
                self.verbose('Evaluation target = {} (recorded {} = {:.2f} %)'.format(self.paras.load, metric, score))
def load_ckpt ( self ) : if self . paras . load : # Load weights ckpt = torch . load ( self . paras . load , map_location = self . device if self . mode == 'train' else 'cpu' ) self . model . load_state_dict ( ckpt [ 'model' ] ) if self . emb_decoder is not None : self . emb_decoder . load_state_dict ( ckpt [ 'emb_decoder' ] ) # if self.amp: #    amp.load_state_dict(ckpt['amp']) # Load task-dependent items metric = "None" score = 0.0 for k , v in ckpt . items ( ) : if type ( v ) is float : metric , score = k , v if self . mode == 'train' : self . step = ckpt [ 'global_step' ] self . optimizer . load_opt_state_dict ( ckpt [ 'optimizer' ] ) self . verbose ( 'Load ckpt from {}, restarting at step {} (recorded {} = {:.2f} %)' . format ( self . paras . load , self . step , metric , score ) ) else : self . model . eval ( ) if self . emb_decoder is not None : self . emb_decoder . eval ( ) self . verbose ( 'Evaluation target = {} (recorded {} = {:.2f} %)' . format ( self . paras . load , metric , score ) )