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.
- __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:
- __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:
- _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 withMLFLOW_ARTIFACTS_SUBDIRS[x]_PATH
. Following type of artifacts are predefined and each will be considered as a subdirectory ofbase_path
ifNone
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:
- _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 makesartifact_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:
Note
it can be used on
seaborn.countplot
tooReference: