Skip to content

Immutable data input fails for MaskedPatchWSIDataset and SlidingPatchWSIDataset #4724

@bhashemian

Description

@bhashemian

The underlying transformations in MaskedPatchWSIDataset and SlidingPatchWSIDataset uses mutability of the data array to enrich the internal data array with additional calculated information. Thus providing data as an immutable will cause an issue for proper functionality of these components.

The typical use for these transforms are as follow:

data = [{"image": "temp_CMU-1.tiff.tiff"}]
patch_dataset_1 = MaskedPatchWSIDataset(data, patch_level=5, patch_size=3)
print(patch_dataset_1.image_data[0])
{'image': 'temp_CMU-1.tiff.tiff', 'patch_size': (3, 3), 'patch_level': 5, 'name': 'temp_CMU-1.tiff.tiff', 'num_patches': 17016, 'mask_size': (257, 359)}

However, if the data come from a dataset that do transforms on immutable variable, the underlying element of input data will change. Please look at the missing fields in the output below comparing to above output.

data = [{"image": "temp_CMU-1.tiff.tiff"}]
dataset = Dataset(data, transform=Lambdad(keys="image", func=lambda x: x[:]))
patch_dataset_2 = MaskedPatchWSIDataset(dataset, patch_level=5, patch_size=3)
print(patch_dataset_2.image_data[0])
{'image': 'temp_CMU-1.tiff.tiff'}

This can be simply addressed by exhausting the dataset and storing the elements:

patch_dataset_3 = MaskedPatchWSIDataset(list(dataset), patch_level=5, patch_size=3)
print(patch_dataset_3.image_data[0])
{'image': 'temp_CMU-1.tiff.tiff', 'patch_size': (3, 3), 'patch_level': 5, 'name': 'temp_CMU-1.tiff.tiff', 'num_patches': 17016, 'mask_size': (257, 359)}

Metadata

Metadata

Assignees

Labels

Pathology/MicroscopyDigital Pathology and Microscopy related

Type

No type

Projects

Status

💯 Complete

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions