def load(self, path):
    m_path = (os.path.join(path, 'model.pt') if os.path.isdir(path) else path)
    if (not os.path.exists(m_path)):
        m_path = os.path.join(path, 'model_state.pt')
        self._load_state_dict(m_path)
    else:
        self.model = torch.load(m_path, map_location=torch.device('cpu'))
    self.model.to(self.device)
    self._parallelize()
    log_strs = ['model from {}'.format(m_path)]
    self.optimizer = self._init_optimizer()
    self.scheduler = self._init_scheduler(self.optimizer, self.optimizer_scheduler_cfg)
    o_path = (os.path.join(path, 'optimizer.pt') if os.path.isdir(path) else None)
    if (o_path and os.path.exists(o_path)):
        checkpoint = torch.load(o_path, map_location=torch.device('cpu'))
        self.optimizer.load_state_dict(checkpoint['optimizer'])
        log_strs.append('optimizer from {}'.format(o_path))
        self.last_epoch = checkpoint['epoch']
    if (self.scheduler is not None):
        s_path = (os.path.join(path, 'scheduler.pt') if os.path.isdir(path) else None)
        if (s_path and os.path.exists(s_path)):
            self.scheduler.load_state_dict(torch.load(s_path, map_location=torch.device('cpu')))
            log_strs.append('scheduler from {}'.format(s_path))
    self.logger.info('param size = %f M', (utils.count_parameters(self.model) / 1000000.0))
    self.logger.info('Loaded checkpoint from %s: %s', path, ', '.join(log_strs))
    self.logger.info('Last epoch: %d', self.last_epoch)
def load(self, path):
    m_path = (os.path.join(path, 'model.pt') if os.path.isdir(path) else path)
    if (not os.path.exists(m_path)):
        m_path = os.path.join(path, 'model_state.pt')
        self._load_state_dict(m_path)
    else:
        self.model = torch.load(m_path, map_location=torch.device('cpu'))
    self.model.to(self.device)
    self._parallelize()
    log_strs = ['model from {}'.format(m_path)]
    self.optimizer = self._init_optimizer()
    self.scheduler = self._init_scheduler(self.optimizer, self.optimizer_scheduler_cfg)
    o_path = (os.path.join(path, 'optimizer.pt') if os.path.isdir(path) else None)
    if (o_path and os.path.exists(o_path)):
        checkpoint = torch.load(o_path, map_location=torch.device('cpu'))
        self.optimizer.load_state_dict(checkpoint['optimizer'])
        log_strs.append('optimizer from {}'.format(o_path))
        self.last_epoch = checkpoint['epoch']
    if (self.scheduler is not None):
        s_path = (os.path.join(path, 'scheduler.pt') if os.path.isdir(path) else None)
        if (s_path and os.path.exists(s_path)):
            self.scheduler.load_state_dict(torch.load(s_path, map_location=torch.device('cpu')))
            log_strs.append('scheduler from {}'.format(s_path))
    self.logger.info('param size = %f M', (utils.count_parameters(self.model) / 1000000.0))
    self.logger.info('Loaded checkpoint from %s: %s', path, ', '.join(log_strs))
    self.logger.info('Last epoch: %d', self.last_epoch)