def test_sequence(self): test_dataset = ZipDataset( datasets=[Dataset_(5), Dataset_(5), Dataset_(5)], transform=None) subset = test_dataset[[1, 3, 4]] self.assertEqual(subset[-1], (4, 4, 4)) self.assertEqual(len(subset), 3)
def test_slicing(self): test_dataset = ZipDataset( datasets=[Dataset_(5), Dataset_(5), Dataset_(5)], transform=None) subset = test_dataset[0:2] self.assertEqual(subset[-1], (1, 1, 1)) self.assertEqual(len(subset), 2)
def __init__( self, inputZ01: Sequence, inputZ02: Sequence, inputZ03: Sequence, inputZ04: Sequence, inputZ05: Sequence, inputZ06: Sequence, inputZ07: Sequence, targetC01: Sequence, targetC02: Sequence, targetC03: Sequence, roi_size: int, n_samples: int, inputZ01_transform: Optional[Callable] = None, inputZ02_transform: Optional[Callable] = None, inputZ03_transform: Optional[Callable] = None, inputZ04_transform: Optional[Callable] = None, inputZ05_transform: Optional[Callable] = None, inputZ06_transform: Optional[Callable] = None, inputZ07_transform: Optional[Callable] = None, targetC01_transform: Optional[Callable] = None, targetC02_transform: Optional[Callable] = None, targetC03_transform: Optional[Callable] = None, ) -> None: """ Initializes the dataset with the filename lists. The transform `img_transform` is applied to the images and `seg_transform` to the segmentations. """ items = [(inputZ01, inputZ01_transform), (inputZ02, inputZ02_transform), (inputZ03, inputZ03_transform), (inputZ04, inputZ04_transform), (inputZ05, inputZ05_transform), (inputZ06, inputZ06_transform), (inputZ07, inputZ07_transform), (targetC01, targetC01_transform), (targetC02, targetC02_transform), (targetC03, targetC03_transform)] self.roi_size = roi_size self.n_samples = n_samples self.set_random_state(seed=get_seed()) sampler = RandSpatialCropSamples(roi_size=(self.roi_size, self.roi_size), num_samples=self.n_samples, random_center=True, random_size=False) datasets = [PatchDataset(dataset=x[0], patch_func=sampler, samples_per_image=self.n_samples, transform=x[1]) for x in items if x[0] is not None] self.dataset = datasets[0] if len(datasets) == 1 else ZipDataset(datasets) self._seed = 0 # transform synchronization seed
def __init__(self, inputZ01: Sequence, inputZ02: Sequence, inputZ03: Sequence, inputZ04: Sequence, inputZ05: Sequence, inputZ06: Sequence, inputZ07: Sequence, targetC01: Sequence, targetC02: Sequence, targetC03: Sequence, inputZ01_transform: Optional[Callable] = None, inputZ02_transform: Optional[Callable] = None, inputZ03_transform: Optional[Callable] = None, inputZ04_transform: Optional[Callable] = None, inputZ05_transform: Optional[Callable] = None, inputZ06_transform: Optional[Callable] = None, inputZ07_transform: Optional[Callable] = None, targetC01_transform: Optional[Callable] = None, targetC02_transform: Optional[Callable] = None, targetC03_transform: Optional[Callable] = None) -> None: """ Initializes the dataset with the filename lists. The transform `img_transform` is applied to the images and `seg_transform` to the segmentations. """ items = [ (inputZ01, inputZ01_transform), (inputZ02, inputZ02_transform), (inputZ03, inputZ03_transform), (inputZ04, inputZ04_transform), (inputZ05, inputZ05_transform), (inputZ06, inputZ06_transform), (inputZ07, inputZ07_transform), (targetC01, targetC01_transform), (targetC02, targetC02_transform), (targetC03, targetC03_transform) ] self.set_random_state(seed=get_seed()) datasets = [Dataset(x[0], x[1]) for x in items if x[0] is not None] self.dataset = datasets[0] if len(datasets) == 1 else ZipDataset( datasets) self._seed = 0 # transform synchronization seed
def test_value(self, datasets, transform, expected_output, expected_length): test_dataset = ZipDataset(datasets=datasets, transform=transform) self.assertEqual(test_dataset[0], expected_output) self.assertEqual(len(test_dataset), expected_length)