Skip to content

Instantly share code, notes, and snippets.

@crowsonkb
Created January 13, 2021 00:25
Show Gist options
  • Save crowsonkb/b1bcbcf20b9dfa63a1248a005e227c46 to your computer and use it in GitHub Desktop.
Save crowsonkb/b1bcbcf20b9dfa63a1248a005e227c46 to your computer and use it in GitHub Desktop.
from torch.nn import functional as F
from torchvision import transforms
def random_shift(input, max_shift, mode='replicate', value=0):
padded = F.pad(input, max_shift, mode=mode, value=value)
return transforms.RandomCrop(input.shape[2:])(padded)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment