| 202 | |
| 203 | |
| 204 | def xpatch_square(self, features, mask_size): |
| 205 | """ |
| 206 | """ |
| 207 | # square |
| 208 | x1_max = features.shape[2] - mask_size |
| 209 | y1_max = features.shape[3] - mask_size |
| 210 | num_masks = 1 |
| 211 | for i in range(num_masks): |
| 212 | mask_x1 = torch.randint(x1_max, (1,)) |
| 213 | mask_y1 = torch.randint(y1_max, (1,)) |
| 214 | mask_x2 = mask_x1 + mask_size |
| 215 | mask_y2 = mask_y1 + mask_size |
| 216 | new_idx = torch.randperm(features.shape[0]) |
| 217 | features[:, :, mask_x1 : mask_x2, mask_y1 : mask_y2] = features[new_idx, :, mask_x1 : mask_x2, mask_y1 : mask_y2] |
| 218 | return features |
| 219 | |
| 220 | |
| 221 | class cutout_patch: |