def _load_cache_item(self, item, transforms): for _transform in transforms: # execute all the deterministic transforms if isinstance( _transform, Randomizable) or not isinstance(_transform, Transform): break item = apply_transform(_transform, item) return item
def __getitem__(self, index: int): def to_list(x): return list(x) if isinstance(x, (tuple, list)) else [x] data = list() for dataset in self.data: data.extend(to_list(dataset[index])) if self.transform is not None: data = apply_transform(self.transform, data, map_items=False) # transform the list data return data
def __getitem__(self, index: int): self.randomize() meta_data = None img_loader = LoadNifti(as_closest_canonical=self.as_closest_canonical, image_only=self.image_only, dtype=self.dtype) if self.image_only: img = img_loader(self.image_files[index]) else: img, meta_data = img_loader(self.image_files[index]) seg = None if self.seg_files is not None: seg_loader = LoadNifti(image_only=True) seg = seg_loader(self.seg_files[index]) label = None if self.labels is not None: label = self.labels[index] if self.transform is not None: if isinstance(self.transform, Randomizable): self.transform.set_random_state(seed=self._seed) img = apply_transform(self.transform, img) data = [img] if self.seg_transform is not None: if isinstance(self.seg_transform, Randomizable): self.seg_transform.set_random_state(seed=self._seed) seg = apply_transform(self.seg_transform, seg) if seg is not None: data.append(seg) if label is not None: data.append(label) if not self.image_only and meta_data is not None: data.append(meta_data) if len(data) == 1: return data[0] return data
def __getitem__(self, index): if index < self.cache_num: # load data from cache and execute from the first random transform start_run = False data = self._cache[index] for _transform in self.transform.transforms: # pytype: disable=attribute-error if not start_run and not isinstance( _transform, Randomizable) and isinstance( _transform, Transform): continue else: start_run = True data = apply_transform(_transform, data) else: # no cache for this data, execute all the transforms directly data = super(CacheDataset, self).__getitem__(index) return data
def _first_random_and_beyond_transform(self, item_transformed): """ Process the data from before the first random transform to the final state ready for evaluation. Args: item_transformed: The data to be transformed (already processed up to the first random transform) Returns: the transformed element through the random transforms """ start_post_randomize_run = False for _transform in self.transform.transforms: # pytype: disable=attribute-error if (start_post_randomize_run or isinstance(_transform, Randomizable) or not isinstance(_transform, Transform)): start_post_randomize_run = True item_transformed = apply_transform(_transform, item_transformed) return item_transformed
def _pre_first_random_transform(self, item_transformed): """ Process the data from original state up to the first random element. Args: item_transformed: The data to be transformed Returns: the transformed element up to the first identified random transform object """ for _transform in self.transform.transforms: # pytype: disable=attribute-error # execute all the deterministic transforms if isinstance( _transform, Randomizable) or not isinstance(_transform, Transform): break item_transformed = apply_transform(_transform, item_transformed) return item_transformed
def __getitem__(self, index: int): data = self.data[index] if self.transform is not None: data = apply_transform(self.transform, data) return data
def run_post_transform(engine): engine.state.output = apply_transform(post_transform, engine.state.output)