linna.nnutils
Module Contents
Classes
Class that loads hyperparameters from a json file. |
|
A simple class that maintains the running average of a quantity |
Functions
|
Set the logger to log info in terminal and file log_path. |
|
Saves dict of floats in json file |
|
Saves model and training parameters at checkpoint + 'last.pth.tar'. If is_best==True, also saves |
|
Loads model parameters (state_dict) from file_path. If optimizer is provided, loads state_dict of |
|
Create a pyplot plot and save to buffer. |
- class linna.nnutils.Params(json_path)[source]
Class that loads hyperparameters from a json file. Example:
` params = Params(json_path) print(params.learning_rate) params.learning_rate = 0.5 # change the value of learning_rate in params `
- class linna.nnutils.RunningAverage[source]
A simple class that maintains the running average of a quantity
Example:
` loss_avg = RunningAverage() loss_avg.update(2) loss_avg.update(4) loss_avg() = 3 `
- linna.nnutils.set_logger(log_path)[source]
Set the logger to log info in terminal and file log_path. In general, it is useful to have a logger so that every output to the terminal is saved in a permanent file. Here we save it to model_dir/train.log. Example:
` logging.info("Starting training...") `:param log_path: (string) where to log
- linna.nnutils.save_dict_to_json(d, json_path)[source]
Saves dict of floats in json file :param d: (dict) of float-castable values (np.float, int, float, etc.) :param json_path: (string) path to json file
- linna.nnutils.save_checkpoint(state, is_best, checkpoint)[source]
Saves model and training parameters at checkpoint + ‘last.pth.tar’. If is_best==True, also saves checkpoint + ‘best.pth.tar’ :param state: (dict) contains model’s state_dict, may contain other keys such as epoch, optimizer state_dict :param is_best: (bool) True if it is the best model seen till now :param checkpoint: (string) folder where parameters are to be saved
- linna.nnutils.load_checkpoint(checkpoint, model, optimizer=None, device=None, ismpi=False)[source]
Loads model parameters (state_dict) from file_path. If optimizer is provided, loads state_dict of optimizer assuming it is present in checkpoint. :param checkpoint: (string) filename which needs to be loaded :param model: (torch.nn.Module) model for which the parameters are loaded :param optimizer: (torch.optim) optional: resume optimizer from checkpoint