Skip to content

Utils

Source

Utils module.

cwd(path)

Change the current working directory to the given path.

This method can be used to generate files in a specific directory, once out of the context, the working directory is set back to the original one.

Parameters:

Returns:

Examples:

The context is whcnaged within the block and then restored to the original one.

>>> with cwd(my_path):
...     pass # do something

get_careamics_home()

Return the CAREamics home directory.

CAREamics home directory is a hidden folder in home.

Returns:

  • Path

    CAREamics home directory path.

get_logger(name, log_level=logging.INFO, log_path=None)

Create a python logger instance with configured handlers.

Parameters:

  • name (str) –

    Name of the logger.

  • log_level (int, default: INFO ) –

    Log level (info, error etc.), by default logging.INFO.

  • log_path (Optional[Union[str, Path]], default: None ) –

    Path in which to save the log, by default None.

Returns:

get_ram_size()

Get RAM size in mbytes.

Returns:

  • int

    RAM size in mbytes.

get_run_version(root_folder, folder_name)

Get the version run based on experiment folder name.

Versioned folder starts at <folder_name>_0 and is incremented based on the content of the root folder. This method is intended to be used for creating checkpoint folders for each training run, without mixing up checkpoints. It should mimick the csv logger.

Parameters:

  • root_folder (str | Path) –

    The root folder where the versioned folders are located.

  • folder_name (str) –

    The name of the versioned folder.

Returns:

  • int

    The version number for the new run, which is one higher than the highest existing version number. If no versioned folders exist, it returns 0.