(self, checkpoint_path, resume)
Resume from saved checkpoints
        :param checkpoint_path: Checkpoint path to be resumed
Resume from saved checkpoints
        :param checkpoint_path: Checkpoint path to be resumed
Resume from saved checkpoints : param checkpoint_path : Checkpoint path to be resumed
def _load_checkpoint(self, checkpoint_path, resume):
        """
        Resume from saved checkpoints
        :param checkpoint_path: Checkpoint path to be resumed
        """
        self.logger_info("Loading checkpoint: {} ...".format(checkpoint_path))
        checkpoint = torch.load(checkpoint_path, map_location=torch.device('cpu'))
        self.model.load_state_dict(checkpoint['state_dict'], strict=resume)
        if resume:
            self.global_step = checkpoint['global_step']
            self.start_epoch = checkpoint['epoch']
            self.config['lr_scheduler']['args']['last_epoch'] = self.start_epoch
            # self.scheduler.load_state_dict(checkpoint['scheduler'])
            self.optimizer.load_state_dict(checkpoint['optimizer'])
            if 'metrics' in checkpoint:
                self.metrics = checkpoint['metrics']
            if self.with_cuda:
                for state in self.optimizer.state.values():
                    for k, v in state.items():
                        if isinstance(v, torch.Tensor):
                            state[k] = v.to(self.device)
            self.logger_info("resume from checkpoint {} (epoch {})".format(checkpoint_path, self.start_epoch))
        else:
            self.logger_info("finetune from checkpoint {}".format(checkpoint_path))
def _load_checkpoint ( self , checkpoint_path , resume ) : self . logger_info ( "Loading checkpoint: {} ..." . format ( checkpoint_path ) ) checkpoint = torch . load ( checkpoint_path , map_location = torch . device ( 'cpu' ) ) self . model . load_state_dict ( checkpoint [ 'state_dict' ] , strict = resume ) if resume : self . global_step = checkpoint [ 'global_step' ] self . start_epoch = checkpoint [ 'epoch' ] self . config [ 'lr_scheduler' ] [ 'args' ] [ 'last_epoch' ] = self . start_epoch # self.scheduler.load_state_dict(checkpoint['scheduler']) self . optimizer . load_state_dict ( checkpoint [ 'optimizer' ] ) if 'metrics' in checkpoint : self . metrics = checkpoint [ 'metrics' ] if self . with_cuda : for state in self . optimizer . state . values ( ) : for k , v in state . items ( ) : if isinstance ( v , torch . Tensor ) : state [ k ] = v . to ( self . device ) self . logger_info ( "resume from checkpoint {} (epoch {})" . format ( checkpoint_path , self . start_epoch ) ) else : self . logger_info ( "finetune from checkpoint {}" . format ( checkpoint_path ) )