holocron.transforms

holocron.transforms provides PIL and PyTorch tensor transformations.

class holocron.transforms.Resize(size: Tuple[int, int], mode: ResizeMethod = ResizeMethod.SQUISH, pad_mode: str = 'constant', **kwargs: Any)[source]

Implements a more flexible resizing scheme.

https://github.com/frgfm/Holocron/releases/download/v0.2.1/resize_example.png
>>> from holocron.transforms import Resize
>>> pil_img = ...
>>> tf = Resize((224, 224), mode="pad")
>>> resized_img = tf(pil_img)
Parameters:
  • size – the desired height and width of the image in pixels

  • mode – the resizing scheme (“squish” is similar to PyTorch, “pad” will preserve the aspect ratio and pad)

  • pad_mode – padding mode when mode is “pad”

  • kwargs – the keyword arguments of torchvision.transforms.Resize

Returns:

the resized image

forward(image: Image | Tensor) Image | Tensor[source]
Parameters:

img (PIL Image or Tensor) – Image to be scaled.

Returns:

Rescaled image.

Return type:

PIL Image or Tensor

class holocron.transforms.RandomZoomOut(size: Tuple[int, int], scale: Tuple[float, float] = (0.5, 1.0), **kwargs: Any)[source]

Implements a size reduction of the orignal image to provide a zoom out effect.

https://github.com/frgfm/Holocron/releases/download/v0.2.1/randomzoomout_example.png
>>> from holocron.transforms import RandomZoomOut
>>> pil_img = ...
>>> tf = RandomZoomOut((224, 224), scale=(0.3, 1.))
>>> resized_img = tf(pil_img)
Parameters:
  • size – the desired height and width of the image in pixels

  • scale – the range of relative area of the projected image to the desired size

  • kwargs – the keyword arguments of torchvision.transforms.functional.resize

Returns:

the resized image

forward(image: Image | Tensor) Image | Tensor[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.