Adds support for resizing and cropping `TensorImage` and `TensorMask` as an `item_tfm` to fast.ai.

Implementation Patches and Methods

Augmentations patched: RandomCrop, CropPad, Resize, RandomResizedCrop, & RatioResize.

For details on how they work, see the fast.ai documentation.

RandomCrop.encodes[source]

RandomCrop.encodes(x:TensorImage | TensorMask)

Extends RandomCrop to TensorImage & TensorMask

_,axs = plt.subplots(1,3,figsize=(12,4))
f = RandomCrop(200)
for ax in axs: f(img).show(ctx=ax)

On the validation set, a center crop is always taken.

_,axs = plt.subplots(1,3,figsize=(12,4))
for ax in axs: f(img, split_idx=1).show(ctx=ax)

CropPad.encodes[source]

CropPad.encodes(x:TensorImage | TensorMask)

Extends CropPad to TensorImage & TensorMask

_,axs = plt.subplots(1,3,figsize=(12,4))
for ax,mode in zip(axs.flatten(), [PadMode.Zeros, PadMode.Border, PadMode.Reflection]):
    img.crop_pad((600,700), pad_mode=mode).show(ctx=ax, title=mode)

Resize.encodes[source]

Resize.encodes(x:TensorImage | TensorMask)

Extends Resize to TensorImage & TensorMask

_,axs = plt.subplots(1,3,figsize=(12,4))
for ax,method in zip(axs.flatten(), [ResizeMethod.Squish, ResizeMethod.Pad, ResizeMethod.Crop]):
    rsz = Resize(256, method=method)
    rsz(img, split_idx=0).show(ctx=ax, title=method)

On the validation set, the crop is always a center crop (on the dimension that's cropped).

_,axs = plt.subplots(1,3,figsize=(12,4))
for ax,method in zip(axs.flatten(), [ResizeMethod.Squish, ResizeMethod.Pad, ResizeMethod.Crop]):
    rsz(img, split_idx=1).show(ctx=ax, title=method)

RandomResizedCrop.encodes[source]

RandomResizedCrop.encodes(x:TensorImage | TensorMask)

Extends RandomResizedCrop to TensorImage & TensorMask

crop = RandomResizedCrop(256)
_,axs = plt.subplots(3,3,figsize=(9,9))
for ax in axs.flatten():
    crop(img).show(ctx=ax)