Top-Level Utilities¶
The utils module provides additional utilities not specific to configuration, metrics, or callbacks.
- ucs.utils.apply_color_map(mask, id2color)[source]¶
Map class indices to RGB values for visualization.
- ucs.utils.find_checkpoint(checkpoints_dir, version)[source]¶
Locate the single checkpoint file in the specified versioned directory.
- Parameters:
- Returns:
Absolute path to the checkpoint file.
- Return type:
- Raises:
CheckpointDirectoryError – If the checkpoint directory is missing or invalid.
CheckpointNotFoundError – If no checkpoint file is found.
MultipleCheckpointsError – If multiple checkpoint files are found.
- ucs.utils.get_last_version(logs_dir)[source]¶
Get the last version number for the logs directory containing only ‘version_[n]’ folders.
- ucs.utils.get_next_version(logs_dir)[source]¶
Get the next version number for the logs directory containing only ‘version_[n]’ folders.
- ucs.utils.load_class_weights(class_weights_dir)[source]¶
Load precomputed class weights from a file and return as a torch tensor.
- ucs.utils.plot_image_and_mask(image, mask, id2color)[source]¶
Display an image and its corresponding mask side by side.
- ucs.utils.save_class_weights(class_weights_dir, class_weights)[source]¶
Save computed class weights to a file.
- ucs.utils.save_confusion_matrix_plot(conf_matrix, labels, save_path, metrics=None, title='Confusion Matrix')[source]¶
Save a confusion matrix plot to a file using sklearn’s ConfusionMatrixDisplay.
- Parameters:
conf_matrix (
ndarray) – Confusion matrix containing y_true (actual labels) and y_pred (predicted labels).labels (
list) – List of class labels.save_path (
Path) – path to save the confusion matrix plot.metrics (
dict, optional) – Dictionary of metrics to annotate below the confusion matrix. Defaults to None.title (
str, optional) – Title for the confusion matrix plot. Defaults to “Confusion Matrix”.