Dictionary-based version :py:class:`monai.transforms.CutMix`. Notice that the mixture weights will be the same for all entries for consistency, i.e. images and labels must be aggregated with the same weights, but the random crops are not.
| 56 | |
| 57 | |
| 58 | class CutMixd(MapTransform, RandomizableTransform): |
| 59 | """ |
| 60 | Dictionary-based version :py:class:`monai.transforms.CutMix`. |
| 61 | |
| 62 | Notice that the mixture weights will be the same for all entries |
| 63 | for consistency, i.e. images and labels must be aggregated with the same weights, |
| 64 | but the random crops are not. |
| 65 | """ |
| 66 | |
| 67 | def __init__( |
| 68 | self, |
| 69 | keys: KeysCollection, |
| 70 | batch_size: int, |
| 71 | label_keys: KeysCollection | None = None, |
| 72 | alpha: float = 1.0, |
| 73 | allow_missing_keys: bool = False, |
| 74 | ) -> None: |
| 75 | super().__init__(keys, allow_missing_keys) |
| 76 | self.mixer = CutMix(batch_size, alpha) |
| 77 | self.label_keys = ensure_tuple(label_keys) if label_keys is not None else [] |
| 78 | |
| 79 | def set_random_state(self, seed: int | None = None, state: np.random.RandomState | None = None) -> CutMixd: |
| 80 | super().set_random_state(seed, state) |
| 81 | self.mixer.set_random_state(seed, state) |
| 82 | return self |
| 83 | |
| 84 | def __call__(self, data): |
| 85 | d = dict(data) |
| 86 | first_key: Hashable = self.first_key(d) |
| 87 | if first_key == (): |
| 88 | out: dict[Hashable, NdarrayOrTensor] = convert_to_tensor(d, track_meta=get_track_meta()) |
| 89 | return out |
| 90 | self.mixer.randomize(d[first_key]) |
| 91 | for key, label_key in self.key_iterator(d, self.label_keys): |
| 92 | ret = self.mixer(data[key], data.get(label_key, None), randomize=False) |
| 93 | d[key] = ret[0] |
| 94 | if label_key in d: |
| 95 | d[label_key] = ret[1] |
| 96 | return d |
| 97 | |
| 98 | |
| 99 | class CutOutd(MapTransform, RandomizableTransform): |
no outgoing calls
searching dependent graphs…