Utilities

src.helpers.utilities.get_iou_score(y_true, y_pred)[source]

Calculates the Intersection over Union score given a mask and a prediction.

Parameters
  • y_true (array) – the true mask corresponding to the prediction

  • y_pred (array) – the prediction

Return type

float

Returns

IoU

src.helpers.utilities.classification_report(predictions, masks, save_path=None)[source]

Generates a classification report by comparing each mask and prediction in the input list of predictions and masks. If a save path is provided then the classification report is saved. The metrics returned in the report are: IoU, AUC_PR, Precision, Recall, F1, Accuracy, FN, FP, TN, and TP.

Parameters
  • predictions (List[array]) – a list of predictions

  • masks (List[array]) – a list of masks corresponding to the predictions

  • save_path (Optional[str]) – the output path to saved the classifcation report

Return type

DataFrame

Returns

a classification report df

src.helpers.utilities.create_file_name(output_folder_path, output_file_name, i, placeholder_size)[source]

Creates the output folder path if it doesn’t exist. The input number, i, is zero padded according to the placeholder size and appended to the output filename. This filename is appended to the output folder path and returned.

Parameters
  • output_folder_path – the output folder path

  • output_file_name – the filename to which the zero-padded number must be appended

  • i – the number to zero pad

  • placeholder_size – determines how much to zero pad i; i.e. if placeholder size is 3 and i =1, the number used in the filename will be 001

Returns

an output file path

src.helpers.utilities.trim_image_array(image_array, output_size, axis, trim_dir)[source]

Trims an image, either from the start or the end, along a single axis.

Parameters
  • image_array (array) – the input image

  • output_size (int) – the output size of the image; i.e. informs how much of the image to trim

  • axis (str) – one of either “x”, “y” or both

  • trim_dir (int) – the trim direction, either -1 or 1; 1 trims from the start of the image and -1 trims from the end

Return type

array

Returns

the trimmed image

src.helpers.utilities.update_plot_format(default=False)[source]

Updates the matplotlib RC. This function can also be used to set the rc back to the default configuration.

Parameters

default (bool) – whether to set the RC to the custom config or to the default config

Return type

None

Returns

None

src.helpers.utilities.create_subfolders(path, folder)[source]

Creates leaf and mask subfolders at the given base path and folder.

Parameters
  • path (Path) – base path

  • folder (str) – the folder in the path under which the subfolders should be created

Return type

None

Returns

None

src.helpers.utilities.create_sequence_objects(sequence_input)[source]

Creates a list of LeafSequence and MaskSequence objects.

Parameters

sequence_input (Dict) – a dict with the details of how the sequence should be created; this dict can control in which mode the sequence objects are created in

Returns

a list of LeafSequence and a list MaskSequence objects

src.helpers.utilities.load_image_objects(seq_objects, load_images=False, **kwargs)[source]

Creates image object for each sequence object in a list of sequence objects. No object is return but the sequence objects are mutated.

Parameters
  • seq_objects – the list of sequence objects whose images need to be created

  • load_images (bool) – whether image arrays for the created objects should be loaded

  • kwargs – kwargs for loading image, if load_images is true

Return type

None

Returns

None

src.helpers.utilities.trim_sequence_images(seq_objects, x_size_dir_list=None, y_size_dir_list=None, overwrite=False, **kwargs)[source]

Trims either a images in a list MaskSequence or LeafSequence objects. No object is returned but the trim images are saved.

Parameters
  • seq_objects – either a list of MaskSequence or LeafSequence objects

  • y_size_dir_list (Optional[List[Tuple[int, int]]]) – a list of tuples; each tuple is in the format of (output size, trim_direction), where trim direction is either 1 or -1, which indicates to trim from either the top or bottom respectively

  • x_size_dir_list (Optional[List[Tuple[int, int]]]) – a list of tuples; each tuple is in the format of (output size, trim_direction), where trim direction is either 1 or -1, which indicates to trim from either the left or right respectively

  • overwrite (bool) – whether tiles that exist at the same file path should be overwritten

  • kwargs – kwargs for loading the images in the sequence object

Return type

None

Returns

None

src.helpers.utilities.parse_arguments()[source]

Argument parser

Return type

Namespace

Returns

An argparse namespace

src.helpers.utilities.print_options_dict(output_dict)[source]

Print a formatted version of the results of the output dict generated by the input prompt

Parameters

output_dict (Dict) – the output dict to print

Return type

None

Returns

None

src.helpers.utilities.requirements(operation)[source]

Used to add the requirements for a particular operation to the input prompt.

Parameters

operation (int) – the operation whose requirements should be printed

Return type

None

Returns

None

src.helpers.utilities.interactive_prompt()[source]

Interactive prompt which allows users to interact with the code base. The results are returned as a dict. There is an option, through the prompt, to save the input as a json to be used again.

Return type

Dict

Returns

None