= plt.subplots(1,3,figsize=(12,4))
_,axs = RandomCrop(200)
f for ax in axs: f(img).show(ctx=ax)
Tensor Item Transforms
Adds support for resizing and cropping
TensorImage
and TensorMask
as an item_tfm
Implementation Patches and Methods
Augmentations patched: RandomCrop
, CropPad
, Resize
, RandomResizedCrop
, & RatioResize
.
Note
These are all patched extensions of the fastai.vision.augment item transforms.
For details on how they work, see the fastai documentation.
RandomCrop
encodes
encodes (x:Union[fastai.torch_core.TensorImage,fastai.torch_core.TensorM ask])
Extends RandomCrop to TensorImage
& TensorMask
On the validation set, a center crop is always taken.
= plt.subplots(1,3,figsize=(12,4))
_,axs for ax in axs: f(img, split_idx=1).show(ctx=ax)
CropPad
encodes
encodes (x:Union[fastai.torch_core.TensorImage,fastai.torch_core.TensorM ask])
Extends CropPad to TensorImage
& TensorMask
= plt.subplots(1,3,figsize=(12,4))
_,axs for ax,mode in zip(axs.flatten(), [PadMode.Zeros, PadMode.Border, PadMode.Reflection]):
600,700), pad_mode=mode).show(ctx=ax, title=mode) img.crop_pad((
Resize
encodes
encodes (x:Union[fastai.torch_core.TensorImage,fastai.torch_core.TensorM ask])
Extends Resize to TensorImage
& TensorMask
= plt.subplots(1,3,figsize=(12,4))
_,axs for ax,method in zip(axs.flatten(), [ResizeMethod.Squish, ResizeMethod.Pad, ResizeMethod.Crop]):
= Resize(256, method=method)
rsz =0).show(ctx=ax, title=method) rsz(img, split_idx
On the validation set, the crop is always a center crop (on the dimension that’s cropped).
= plt.subplots(1,3,figsize=(12,4))
_,axs for ax,method in zip(axs.flatten(), [ResizeMethod.Squish, ResizeMethod.Pad, ResizeMethod.Crop]):
=1).show(ctx=ax, title=method) rsz(img, split_idx
RandomResizedCrop
encodes
encodes (x:Union[fastai.torch_core.TensorImage,fastai.torch_core.TensorM ask])
Extends RandomResizedCrop to TensorImage
& TensorMask
= RandomResizedCrop(256)
crop = plt.subplots(3,3,figsize=(9,9))
_,axs for ax in axs.flatten():
=ax) crop(img).show(ctx
Squish is used on the validation set, removing val_xtra
proportion of each side first.
= plt.subplots(1,3,figsize=(12,4))
_,axs for ax in axs.flatten():
= crop(img, split_idx=1).show(ctx=ax) cropped
RatioResize
encodes
encodes (x:Union[fastai.torch_core.TensorImage,fastai.torch_core.TensorM ask])
Extends RatioResize to TensorImage
& TensorMask
256)(img).show() RatioResize(
<AxesSubplot:>