datamodules.DivaHisDB.utils package
Submodules
datamodules.DivaHisDB.utils.functional module
- gt_to_int_encoding(matrix: Tensor, class_encodings: List[int]) Tensor [source]
Convert ground truth tensor to integer encoded matrix
- Parameters:
matrix (torch.Tensor) – Image as a tensor of size [C x H x W] (BGR)
class_encodings (List[int]) – class encoding so which class (index) has what value (element)
- Returns:
integer encoded matrix
- Return type:
torch.Tensor
- gt_to_one_hot(matrix: Tensor, class_encodings: List[int])[source]
Convert ground truth tensor or numpy matrix to one-hot encoded matrix
- Parameters:
matrix (torch.Tensor or np.ndarray) – float tensor from to_tensor() or numpy array shape (C x H x W) in the range [0.0, 1.0] or shape (H x W x C) BGR
class_encodings (List[int]) – List of int Blue channel values that encode the different classes
- Returns:
Tensor of size [#C x H x W] sparse one-hot encoded multi-class matrix, where #C is the number of classes
- Return type:
torch.LongTensor
datamodules.DivaHisDB.utils.image_analytics module
- get_analytics(input_path: Path, data_folder_name: str, gt_folder_name: str, get_gt_data_paths_func) Tuple[Dict[str, Any], Dict[str, Any]] [source]
Get the analytics for the dataset. If the analytics file is not present, it will be computed and saved.
- Parameters:
input_path (Path) – Path to the root of the dataset
data_folder_name (str) – Name of the folder containing the data
gt_folder_name (str) – Name of the folder containing the ground truth
get_gt_data_paths_func (Callable) – Function to get the paths to the data and ground truth
- Returns:
Tuple of analytics for the data and ground truth
- Return type:
Tuple[Dict[str, Any], Dict[str, Any]]
- get_class_weights(input_folder, workers=4) List[float] [source]
Get the weights proportional to the inverse of their class frequencies. The vector sums up to 1
- Parameters:
input_folder (Path) – Path to the dataset folder (see above for details)
workers (int) – Number of workers to use for the mean/std computation
- Returns:
The weights vector as a 1D array normalized (sum up to 1)
- Return type:
List[float]
datamodules.DivaHisDB.utils.output_tools module
- output_to_class_encodings(output, class_encodings, perform_argmax=True)[source]
This function converts the output prediction matrix to an image with the colors of the class encodings.
- Parameters:
output (np.array of size [#C x H x W]) – output prediction of the network for a full-size image, where #C is the number of classes
class_encodings (list) – Contains the range of encoded classes
perform_argmax (bool) – perform argmax on input data
- Returns:
np.array of size [H x W] (BGR)
- save_output_page_image(image_name, output_image, output_folder: Path, class_encoding)[source]
Helper function to save the output during testing in the DIVAHisDB format
- Parameters:
image_name (str) – name of the image that is saved
output_image (np.array of size [#C x H x W]) – output image at full size
output_folder (Path) – path to the output folder for the test data
class_encoding (list) – list with the class encodings
- Returns:
mean iou of this image
- Return type:
float