Sometimes you need may to apply the same transform to different tensors. The idea is to get a sample and then apply it with apply() as often as needed. You need to call this method everytime you apply the transform to a new batch.
(self, data=None)
| 48 | raise NotImplementedError() |
| 49 | |
| 50 | def randomize(self, data=None) -> None: |
| 51 | """ |
| 52 | Sometimes you need may to apply the same transform to different tensors. |
| 53 | The idea is to get a sample and then apply it with apply() as often |
| 54 | as needed. You need to call this method everytime you apply the transform to a new |
| 55 | batch. |
| 56 | """ |
| 57 | super().randomize(None) |
| 58 | self._params = ( |
| 59 | torch.from_numpy(self.R.beta(self.alpha, self.alpha, self.batch_size)).type(torch.float32), |
| 60 | self.R.permutation(self.batch_size), |
| 61 | [torch.from_numpy(self.R.randint(0, d, size=(1,))) for d in data.shape[2:]] if data is not None else [], |
| 62 | ) |
| 63 | |
| 64 | |
| 65 | class MixUp(Mixer): |