carate.utils package

Submodules

carate.utils.convert_to_json module

Module for handling config files used to start the training and evaluation process

author:

Julian M. Kleber

carate.utils.convert_to_json.convert_py_to_json(file_name: str, out_name: str | None = None) Dict[str, Any][source]

The convert_py_to_json function takes in a file name and an output file name. It reads the input file, which is assumed to be a .py config file with key value pairs separated by spaces. The function then converts the key value pairs into a dictionary and saves it as json format in the output filename.

Parameters:
  • file_name:str – Used to Specify the file name of the.

  • out_name:str – Used to Specify the name of the output file.

Returns:

A dictionary with the same information as the file.

Doc-author:

Julian M. Kleber

carate.utils.convert_to_json.read_file(file_name: str) List[str][source]

The read_file function takes a file name as input and returns the contents of that file as a list of strings. The function also formats the code using black before reading it in.

Parameters:

file_name:str – Used to Specify the file name.

Returns:

A list of strings.

Doc-author:

Julian M. Kleber

carate.utils.convert_to_json.sanitize_raw_py(raw_input: List[str]) List[str][source]

The sanitize_raw_py function takes in a list of strings and returns a list of strings. The function removes all newline characters from the input, as well as any quotation marks or apostrophes.

Parameters:

raw_input:list[str] – Used to Specify the type of data that is expected to be passed into the function.

Returns:

A list of strings.

Doc-author:

Julian M. Kleber

carate.utils.model_files module

Utility file for model checkpoints file operations

author:

Julian M. Kleber

carate.utils.model_files.get_latest_checkpoint(search_dir: str, num_cv: int, epoch: int) str[source]
carate.utils.model_files.load_model(model_path: str, model_net: Type[Module]) Type[Module][source]

The load_model function takes in a model_path, model_params_path and the type of network to be loaded. It then loads the parameters from the params file into a dictionary and uses that to create an instance of the specified network. It then loads in the state dict from PATH and sets it as eval mode.

Parameters:
  • model_path:str – Used to specify the path to the model file.

  • model_params_path:str – Used to load the model parameters from a file.

  • model_net:Type[torch.nn.Module] – Used to specify the type of model that is being loaded.

Returns:

A model that is loaded with the parameters in the path.

Doc-author:

Julian M. Kleber

carate.utils.model_files.load_model_parameters(model_params_file_path: str) Dict[Any, Any][source]

The load_model_parameters function loads the model parameters from a JSON file.

Parameters:
  • model_params_file_path (str) – The path to the JSON file containing the model parameters.

  • model_params_file_path:str – Used to Specify the file path of the model parameters.

Returns:

A dictionary of all of the loaded model parameters.

Return type:

dict

Returns:

A dictionary of model parameters.

Doc-author:

Julian M. Kleber

carate.utils.model_files.load_model_training_checkpoint(checkpoint_path: str, model_net: Type[Module], optimizer: Type[Optimizer]) Tuple[Model, Optimizer][source]
carate.utils.model_files.save_model(result_save_dir: str, dataset_name: str, num_cv: int, num_epoch: int, model_net: Type[Module]) None[source]

The save_model function saves the model to a file.

The save_model function saves the model to a file. The filename is constructed from the dataset name, number of cross-validation folds, and number of epochs trained on.

Parameters:
  • result_save_dir:str – Used to specify the directory where the model will be saved.

  • dataset_name:str – Used to name the file.

  • num_cv:int – Used to make the filename unique.

  • num_epoch – Used to save the model after a certain number of epochs.

  • model_net:Type[torch.nn.Module] – Used to save the model.

:param : Used to specify the directory where the model will be saved. :return: The path of the saved model.

Doc-author:

Julian M. Kleber

carate.utils.model_files.save_model_parameters(model_net: Model, save_dir: str) None[source]

The save_model_parameters function saves the model architecture to a csv file.

Args:

model_net (torch.nn.Module): The neural network that is being used for training and testing, e.g., CNN() or RNN(). save_path (str): The path where the json file will be saved to, e.g., “./model/”.

Returns: None

Parameters:
  • model_net:Type[torch.nn.Module] – Used to specify the type of model that is being used.

  • save_path:str – Used to save the model architecture in a json file.

Returns:

A dictionary of the model architecture (model_architecture).

Doc-author:

Julian M. Kleber

carate.utils.model_files.save_model_training_checkpoint(result_save_dir: str, dataset_name: str, num_cv: int, num_epoch: int, model_net: Type[Module], optimizer: Type[Optimizer], loss: float, override: bool) None[source]

carate.utils.training_result_parser module

Module for parsing training results

author:

Julian M. Kleber

carate.utils.training_result_parser.get_accuracy(json_object: Dict[Any, List[float]]) List[float][source]
The get_accuracy function takes in a json object and returns the accuracy of the model.
Args:

json_object (dict): A dictionary containing all of the information from a single run.

Returns:

List[float]: The accuracy for each epoch during training.

Parameters:

json_object:dict – Used to Specify the type of the parameter.

Returns:

A list of floats.

Doc-author:

Trelent

carate.utils.training_result_parser.get_auc(json_object: Dict[Any, List[float]]) List[float][source]
carate.utils.training_result_parser.get_loss_json(json_object: Dict[Any, List[float]]) List[float][source]

The get_loss_json function takes in a json object and returns the loss value from that json object.

Parameters:

json_object:dict – Used to Specify that the function takes a dictionary as an argument.

Returns:

A list of dictionaries.

Doc-author:

Trelent

carate.utils.training_result_parser.load_training_from_json_file(file_path: str) Dict[Any, Any][source]

The load_training_from_json_file function loads a training result from a JSON file.

Parameters:

file_path:str – Used to Specify the path to the file that you want to load.

Returns:

A dictionary.

Doc-author:

Trelent

Module contents