(cls, task_name, checkpoint, **kwargs)
return model, hparams
Loads a model from a checkpoint. Also loads hyperparams
        Parameters:
            task_name: Name of the task. Needed to determine model dir
            checkpoint: Number indicating the checkpoint. -1 to load latest
            **kwargs: Additional key-value args passed to constructor
Loads a model from a checkpoint. Also loads hyperparams
        Parameters:
            task_name: Name of the task. Needed to determine model dir
            checkpoint: Number indicating the checkpoint. -1 to load latest
            **kwargs: Additional key-value args passed to constructor
Loads a model from a checkpoint . Also loads hyperparams Parameters : task_name : Name of the task . Needed to determine model dir checkpoint : Number indicating the checkpoint . - 1 to load latest ** kwargs : Additional key - value args passed to constructor
def load(cls, task_name, checkpoint, **kwargs):
        """
        Loads a model from a checkpoint. Also loads hyperparams
        Parameters:
            task_name: Name of the task. Needed to determine model dir
            checkpoint: Number indicating the checkpoint. -1 to load latest
            **kwargs: Additional key-value args passed to constructor
        """
        model_dir = gen_model_dir(task_name, cls)
        hparams_path = os.path.join(model_dir, HYPERPARAMS_FILE)

        if not os.path.exists(hparams_path):
            raise OSError('HParams file not found')

        hparams = torch.load(hparams_path)
        logger.info('Hyperparameters: {}'.format(str(hparams)))

        model = cls(hparams, **kwargs)
        if torch.cuda.is_available():
            model = model.cuda()

        if checkpoint == -1:
            # Find latest checkpoint file
            files = glob.glob(os.path.join(model_dir, CHECKPOINT_GLOB))
            if not files:
                raise OSError('Checkpoint files not found')
            files.sort(key=os.path.getmtime, reverse=True)
            checkpoint_path = files[0]
        else:
            checkpoint_path = os.path.join(model_dir, CHECKPOINT_FILE.format(checkpoint))
            if not os.path.exists(checkpoint_path):
                raise OSError('File not found: {}'.format(checkpoint_path))

        logger.info('Loading from {}'.format(checkpoint_path))
        # Load the model
        model.load_state_dict(torch.load(checkpoint_path))

        return model, hparams
def load ( cls , task_name , checkpoint , * * kwargs ) : model_dir = gen_model_dir ( task_name , cls ) hparams_path = os . path . join ( model_dir , HYPERPARAMS_FILE ) if not os . path . exists ( hparams_path ) : raise OSError ( 'HParams file not found' ) hparams = torch . load ( hparams_path ) logger . info ( 'Hyperparameters: {}' . format ( str ( hparams ) ) ) model = cls ( hparams , * * kwargs ) if torch . cuda . is_available ( ) : model = model . cuda ( ) if checkpoint == - 1 : # Find latest checkpoint file files = glob . glob ( os . path . join ( model_dir , CHECKPOINT_GLOB ) ) if not files : raise OSError ( 'Checkpoint files not found' ) files . sort ( key = os . path . getmtime , reverse = True ) checkpoint_path = files [ 0 ] else : checkpoint_path = os . path . join ( model_dir , CHECKPOINT_FILE . format ( checkpoint ) ) if not os . path . exists ( checkpoint_path ) : raise OSError ( 'File not found: {}' . format ( checkpoint_path ) ) logger . info ( 'Loading from {}' . format ( checkpoint_path ) ) # Load the model model . load_state_dict ( torch . load ( checkpoint_path ) ) return model , hparams