Contains all the transforms relevent to deployment in the `fastai` library
from fastcore.test import test_eq

All code and methods originates from the fastai, and this library has only implemented parts particular to inference. Another way of saying this is all the transforms are their validation-counterparts only

General Pillow

load_image[source]

load_image(fn, mode=None, **kwargs)

Open and load a PIL.Image and convert it to mode

class PILBase[source]

PILBase() :: Image

This class represents an image object. To create :py:class:~PIL.Image.Image objects, use the appropriate factory functions. There's hardly ever any reason to call the Image constructor directly.

  • :py:func:~PIL.Image.open
  • :py:func:~PIL.Image.new
  • :py:func:~PIL.Image.frombytes

Pillow Transforms

Image.crop_pad[source]

Image.crop_pad(x:Image, sz, tl=None, orig_sz=None, pad_mode='zeros', resize_mode=2, resize_to=None)

im = PILBase.create('forest.jpg')
test_eq(_get_sz(im), (2048,1368))

class CropPad[source]

CropPad(size, pad_mode='zeros')

Center crop or pad an image to size

cp = CropPad(224)
test_eq(cp(im).size, (224,224))
rc = RandomCrop(224)
test_eq(rc(im).size, (224,224))

class Resize[source]

Resize(size, method='crop', pad_mode='reflection', resample=2)

Resizes an image based on method with pad_mode and resample

r = Resize(224)
test_eq(r(im).size, (224,224))

class RandomResizedCrop[source]

RandomResizedCrop(size, min_scale=0.08, ratio=(0.75, 1.3333333333333333), resample=2, val_xtra=0.14)

Resizes an image randomly to size based on min_scale, ratio, resample, and val_xtra

rrc = RandomResizedCrop(224)
rrc(im)

class RatioResize[source]

RatioResize(max_sz, resample=2)

Resizes while maintaining the aspect ratio

rr = RatioResize(224)
rr(im)

PyTorch Transforms

image2tensor[source]

image2tensor(img)

Transform image to byte tensor in c*h*w dim order.

class ToTensor[source]

ToTensor(is_image=False)

Turn an input into a Tensor

class Normalize[source]

Normalize(mean=None, std=None, axes=(0, 2, 3))

Normalize based on mean and std on axes

class IntToFloatTensor[source]

IntToFloatTensor(div=255.0, div_mask=0.0)

Converts integer to float