datamodules.RGB.utils package
Submodules
datamodules.RGB.utils.functional module
- gt_to_int_encoding(matrix: Tensor, class_encodings: Tensor)[source]
Convert ground truth tensor or numpy matrix to one-hot 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 of size [#C x H x W]
- Return type:
torch.Tensor
- gt_to_one_hot(matrix: Tensor, class_encodings: Tensor)[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.RGB.utils.image_analytics module
- get_analytics(input_path: Path, data_folder_name: str, gt_folder_name: str, train_folder_name: str, get_img_gt_path_list_func: callable, inmem: bool = False, workers: int = 8) Tuple[Dict[str, Any], Dict[str, Any]] [source]
Get the analytics for the dataset. If the analytics file is not complete, it will be computed and saved.
- Parameters:
workers (int) – The amount of workers to use for the mean/std computation
inmem (bool) – If the dataset should be loaded fully into memory
input_path (Path) – Path to the dataset folder
data_folder_name (str) – Name of the folder that contains the data
gt_folder_name (str) – Name of the folder that contains the ground truth
train_folder_name (str) – Name of the folder that contains the training data
get_img_gt_path_list_func (callable) – Function that returns a list of tuples with the image and gt path
- Returns:
- get_class_weights(input_folder: Path, workers=4) ndarray [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:
ndarray[double]
datamodules.RGB.utils.output_tools module
- output_to_class_encodings(output: ndarray, class_encodings: List[Tuple[int]]) ndarray [source]
This function converts the output prediction matrix to an image like it was provided in the ground truth
- Parameters:
output (np.ndarray) – output prediction of the network for a full-size image, where #C is the number of classes
class_encodings (List[Tuple[int]]) – Contains the range of encoded classes
- Returns:
numpy array of size [C x H x W] (BGR) with the classes encoded as in the ground truth
- Return type:
np.ndarray
- save_output_page_image(image_name: str, output_image: ndarray, output_folder: Path, class_encoding: List[Tuple[int]]) None [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.ndarray) – output image at full size [#C x H x W]
output_folder (Path) – path to the output folder for the test data
class_encoding (List[Tuple[int]]) – list with the class encodings