Cutout as described in the paper: Terrance DeVries, Graham W. Taylor. Improved Regularization of Convolutional Neural Networks with Cutout, arXiv:1708.04552 Class derived from :py:class:`monai.transforms.Mixer`. See corresponding documentation for details on the constructor para
| 167 | |
| 168 | |
| 169 | class CutOut(Mixer): |
| 170 | """Cutout as described in the paper: |
| 171 | Terrance DeVries, Graham W. Taylor. |
| 172 | Improved Regularization of Convolutional Neural Networks with Cutout, |
| 173 | arXiv:1708.04552 |
| 174 | |
| 175 | Class derived from :py:class:`monai.transforms.Mixer`. See corresponding |
| 176 | documentation for details on the constructor parameters. Here, alpha not only determines |
| 177 | the mixing weight but also the size of the random rectangles being cut put. |
| 178 | Please refer to the paper for details. |
| 179 | """ |
| 180 | |
| 181 | def apply(self, data: torch.Tensor): |
| 182 | weights, _, coords = self._params |
| 183 | nsamples, _, *dims = data.shape |
| 184 | if len(weights) != nsamples: |
| 185 | raise ValueError(f"Expected batch of size: {len(weights)}, but got {nsamples}") |
| 186 | |
| 187 | mask = torch.ones_like(data) |
| 188 | for s, weight in enumerate(weights): |
| 189 | lengths = [d * sqrt(1 - weight) for d in dims] |
| 190 | idx = [slice(None)] + [slice(c, min(ceil(c + ln), d)) for c, ln, d in zip(coords, lengths, dims)] |
| 191 | mask[s][idx] = 0 |
| 192 | |
| 193 | return mask * data |
| 194 | |
| 195 | def __call__(self, data: torch.Tensor, randomize=True): |
| 196 | data_t = convert_to_tensor(data, track_meta=get_track_meta()) |
| 197 | if randomize: |
| 198 | self.randomize(data) |
| 199 | return convert_to_dst_type(self.apply(data_t), dst=data)[0] |
no outgoing calls
searching dependent graphs…