niklib.utils package#

Submodules#

niklib.utils.loggers module#

class niklib.utils.loggers.Logger(name, level, mlflow_artifacts_base_path, libs=None)[source]#

Bases: Logger

__init__(name, level, mlflow_artifacts_base_path, libs=None)[source]#

Initialize the logger with a name and an optional level.

property mlflow_artifacts_base_path: Path#
__create_artifacts_dir(path)#

Creates an empty dir at path

Parameters:

path (pathlib.Path) – Path to create dir as base artifacts for mlflow

Return type:

None

__str_to_path(string)#

Converts a string of path to pathlib.Path

Parameters:

string (Union[str, pathlib.Path]) – path string or object to convert

Returns:

Path instance of given path string

Return type:

pathlib.Path

_setup_mlflow_artifacts_dirs(base_path, subdirs=None)[source]#

Builds the directories for saving images, logs, and configs as mlflow artifacts

Note

If you are using this class for just flagging the data, you can simply send numerical values (1/*, 2/*)

Parameters:
  • base_path (Union[str, pathlib.Path]) – Base path for artifacts.

  • subdirs (List[str], optional) –

    A list of names of directories that will be subdirectories of base_path for separating different artifacts. These subdirs are available as properties that start with MLFLOW_ARTIFACTS_SUBDIRS[x]_PATH. Following type of artifacts are predefined and each will be considered as a subdirectory of base_path if None is provided:

    • images: images

    • logging prints: logs

    • configs of classes, setting, etc as json files: configs

    • model weights or objects: models

    • mlflow flavor-specific tracked model: MLmodel

    Please use names that only contain characters, numbers and dash/underline.

Return type:

None

_remove_previous_handlers()[source]#

This is used to remove file related handlers on each new run of create_artifact_instance() :rtype: None

Note

Do not forget to remove file handler from all libs, here, libs_logger.

create_artifact_instance(artifact_name=None)[source]#

Creates an entire artifact (mlflow) directory each time it is called

This is used to create artifacts sub directories that each include sub directories such as images, configs, and so on (see _setup_mlflow_artifacts_dirs() for more info) that each will include the artifacts of that type.

Parameters:

artifact_name (str) – a directory name. Please refrain from providing full path and only give a directory name. It is expected that you pass the path as mlflow_artifacts_base_path which makes artifact_name as its sub directory. If None, we use an internal counter and use natural numbers increasing each time this method is called.

niklib.utils.visualization module#

niklib.utils.visualization.add_percentage_axes(ax, n)[source]#

Add percentage on top of bar (matplotlib and seaborn) plots

Parameters:
  • ax (plt.Axes) – the axes to apply this function

  • n (int) – total number of items for computing percentage

Return type:

None

Note

it can be used on seaborn.countplot too

Reference:

Module contents#