Utils#

aitlas.utils.segmentation_losses module#

Loss functions for image segmentation

class DiceLoss[source]#

Bases: Module

Dice Loss for image segmentation. Expects sigmoided inputs and binary targets. ..note:: Implementation from: kaggle.com/bigironsphere/loss-function-library-keras-pytorch

forward(inputs, targets, smooth=1)[source]#
training: bool#
class FocalLoss[source]#

Bases: Module

Focal Loss for image segmentation. Expects sigmoided inputs and binary targets. ..note:: Implementation from: kaggle.com/bigironsphere/loss-function-library-keras-pytorch

ALPHA = 0.8#
GAMMA = 2#
forward(inputs, targets, alpha=0.8, gamma=2)[source]#
training: bool#

aitlas.utils.utils module#

get_class(class_name)[source]#

Returns the class type for a given class name. Expects a string of type module.submodule.Class

current_ts()[source]#

Returns current timestamp in secs

pil_loader(file, convert_to_grayscale=False)[source]#

Opens an image from disk

tiff_loader(file)[source]#

Opens a tiff image from disk

image_loader(file_path, convert_to_grayscale=False)[source]#

Opens an image from disk

Parameters:
  • file_path (str) – path to the image

  • convert_to_grayscale (bool) – whether to convert the image to grayscale

image_invert(file_path, convert_to_grayscale=False)[source]#

Inverts an image from disk

Parameters:
  • file_path (str) – path to the image

  • convert_to_grayscale (bool) – whether to convert the image to grayscale

stringify(obj)[source]#

Stringify whatever object you have

parse_img_id(file_path, orients)[source]#

Parses direction, strip and coordinate components from a SpaceNet6 image filepath.

split_images(images_dir, ext_images, masks_dir, ext_masks, output_dir, target_size)[source]#
load_voc_format_dataset(dir_path, csv_file_path)[source]#

Loads a dataset in the Pascal VOC format. It expects a multilabels.txt file and images in the root folder

has_file_allowed_extension(file_path, extensions)[source]#

Checks if a file is an allowed extension.

Pararm file_path:

path to a file

Parameters:

extensions (list) – list of allowed extensions

Returns:

True if the file is an allowed extension, False otherwise

Return type:

bool

load_folder_per_class_dataset(dir, extensions=None)[source]#
load_aitlas_format_dataset(file_path)[source]#

Reads the images from a CSV. Format: (image_path, class_name)

submit_inria_results(input_dir, output_dir)[source]#
save_best_model(model, model_directory, epoch, optimizer, loss, start, run_id)[source]#

Saves the model on disk :param model: model to save :type model: torch.nn.Module :param model_directory: directory where to save the model :type model_directory: str :param epoch: current epoch :type epoch: int :param optimizer: optimizer used for training :type optimizer: torch.optim.Optimizer :param loss: loss value :type loss: float :param start: start time :type start: float :param run_id: run id :type run_id: str

collate_fn(batch)[source]#