Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Added ability to run segmentation inference module in the test data without or partial ground truth files. #465

Merged
merged 51 commits into from
Jul 5, 2021

Conversation

asantamariapang
Copy link
Contributor

Addressing issue #459: ability to run segmentation model inference on datasets without or partial segmentation files.

Alberto Santamaria-Pang added 3 commits May 21, 2021 13:22
Creates an 'InferencePipeline.Result' object using pre-defined volumes, stores results and evaluates metrics.
Alberto Santamaria-Pang added 3 commits May 25, 2021 15:22
…ultiple ground truth images missing

For inference, given in a test dataset with all, partial, and no segmentation channels, inference will be executed and metrics will be estimated in when segmentation files exist. In overall, the changes involve

1) Setting to true the Boolean flag: "allow_incomplete_labels".
2) Keeping track of missing channels in "convert_channels_to_file_paths".
    * We need to resolve which ground truth file is missing to be able to map back it correctly to the segmentation result from the inference.
3) A label volume is initialize to NaN if the corresponding ground truth file is missing
    * The order is preserved so can be mapped back to corresponding segmentation in the inference.
4) Only label images that are different that NaN are evaluated in the expected order as implemented in the method "metrics.calculate_metrics_per_class".
Summary:
 * For inference, the following cases are implemented
	* No channels associated with mask or ground_truth_ids
	* Some channels associated with mask or ground_truth_ids
	* All channels associated with mask or ground_truth_ids

 * Changes above, do not apply for tor training and validation.

 Description: Major changes involve

 1) Adding an  optional boolean 'allow_incomplete_labels' flag in class 'FullImageDataset'
	1.1) For training and validation, default value of 'allow_incomplete_labels' is False
		1.1.1) If ground truth channels are missing, pipelines exits and reports errors
	1.2) For Inference 'allow_incomplete_labels' is set to true
		1.1.2) If ground truth channels are missing,
			Method 'get_paths_for_channel_ids' returns a list containing corresponding paths (if provided) and None if no ground truth class files files were provided

  2) Class 'Sample', main changes:
	2.1) 'labels' object is optional, to support full/partial number of provided ground class files
		    2.1.1) 	# (Batches if from data loader) x Classes x Z X Y x X, where the first class is background
					labels: Optional[Union[np.ndarray, torch.Tensor]]
	2.2) Added 'missing_labels' list of booleans to indicate if any channel is missing
			2.2.1) missing_labels: List[bool]
			2.3.2) 'missing_labels' keeps the order of corresponding provided or not provided ground truth classes so that they can be correctly mapped back when for report generation
			2.2.2) The length of 'missing_labels' list must be the same as the number of groundtruth classes (list 'ground_truth_ids')

  3) 'load_labels_from_dataset_source', changes:
	3.1)  A label sample object containing ground-truth information if channel is provided
            If no ground-truth channels provided, label is None
            If some ground-truth channels provided are provided, then they are loaded
            Background is loaded if at least one ground-truth channel is provided and is the first element of the tensor
    3.2 ) A list of booleans indicating if ground-truth channel is missing

  4) 'evaluate_model_predictions'
	4.1) If no ground-truth channels provided, then returns: sample.metadata, MetricsDict(hues=config.ground_truth_ids)
	4.2) If some or all ground-truth channel provided, then returns correponsing metrics
	4.3) If all ground-truth classes are provided, then runs 'plot_contours_for_all_classes'

  5) 'calculate_metrics_per_class'
	5.1) From boolean list 'missing_labels' resolves which ground-truth channels corresponds to the segmentation provided by the inference and estimates corresponding metrics

  6) Integrated/fix testing in the following files:
	6.1) test_augmentation.py
	6.2) test_plotting.py
	6.3) test_metrics.py
    6.4) test_inference.py
	6.5) test_dataset.py

  7) Integrated changes in the following dependencies:
	7.1) util.py
	7.2) io_util.py
	7.3) dataset_util.py
	7.4) augmentation.py
	7.5) plotting.py

  8) Added files to account the number of gt classes for training set consists of patients 1, 2, 3, and files id3* are required in unit test test_csv_dataset_as_data_loader
	8.1) id3_channel2.nii.gz"
	8.2) id3_mask.nii.gz"
    8.3) id3_region.nii.gz"
    8.4) id3_channel1.nii.gz"

  9) Test unit that still will be fix:
	9.1) 'test_load_images_from_dataset_source' as currently enforces ground-truth channels
ant0nsc
ant0nsc previously approved these changes Jul 5, 2021
@ant0nsc ant0nsc marked this pull request as ready for review July 5, 2021 15:21
dumbledad
dumbledad previously approved these changes Jul 5, 2021
Copy link
Contributor

@dumbledad dumbledad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, can I review a PR I am assigned to?

@dumbledad dumbledad enabled auto-merge (squash) July 5, 2021 15:29
Shruthi42
Shruthi42 previously approved these changes Jul 5, 2021
@dumbledad dumbledad dismissed stale reviews from Shruthi42, ant0nsc, and themself via 96840e8 July 5, 2021 15:37
@dumbledad dumbledad merged commit d6d67bd into main Jul 5, 2021
@dumbledad dumbledad deleted the alberto/inference branch July 5, 2021 16:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow segmentation model inference to run on datasets without segmentations or partial segmentations
5 participants