Created
January 3, 2019 15:18
-
-
Save jcreinhold/2850d21faf426af06f077375b8a7eafc to your computer and use it in GitHub Desktop.
transforms for fastai
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import singledispatch | |
@faiv.TfmPixel | |
@singledispatch | |
def crop(x, pct, axis:int) -> torch.Tensor: | |
"""" crop a 3d image along an axis """ | |
s = x.shape | |
i0, i1 = int(s[axis]*pct[0]), int(s[axis]*pct[1]) | |
return x[np.newaxis,i0:i1,:,:].contiguous() if axis == 0 else \ | |
x[np.newaxis,:,i0:i1,:].contiguous() if axis == 1 else \ | |
x[np.newaxis,:,:,i0:i1].contiguous() | |
tfms = [crop(pct=(0.20,0.80),axis=2)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment