Additional torchvision image transforms for practical usage.
Switch branches/tags
Nothing to show
Clone or download
Latest commit 2725a1b Sep 13, 2018
Permalink
Failed to load latest commit information.
quadratum more rigoros validation Sep 12, 2018
.gitignore init May 15, 2018
LICENSE init May 15, 2018
README.md faster whiten funcitonal, adding invert functional Jul 29, 2018
setup.py version up Jul 29, 2018

README.md

Quadratum

Additional torchvision image transforms for practical usage.

Just for me. I needed it.

Note that all functors implemented here assumes an input image to be (H, W, C)-size np.uint8, ranged from 0 to 255.

  • Whiten: make all transparent pixels white.

  • Invert: invert RGB values.

  • Dominofy: limits the ratio of an image, like dominos.

  • Contain: contains an image into given canvas (or box, whatever), just like, you know, the background-size: contain; thingi from CSS?

Installation

pip install quadratum

Usage

Similar to all the other transform functors:

from quadratum import transforms as qtrfm
from torchvision import transforms as vtrfm
transform = vtrfm.Compose([
    qtrfm.Whiten(),
    qtrfm.Dominofy(),
    qtrfm.Contain(256),
    vtrfm.ToPILImage(),
    vtrfm.CenterCrop(224),
    vtrfm.ToTensor(),
    vtrfm.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),
])

or, you can use some pre-defined transformers:

from skimage.io import imread
from quadratum.transformer import Transformer
transform = Transformer('resnet')
image = imread('image.png')  # image.shape => (640, 960, 4)
x = transform(image)  # x.size() => torch.Size([3, 224, 224])

"Quadratum" means "square" in Latin. I wanted to make any noisy user-input images into fine-nice-good-well-godlike-heaven-deep-learning-applicable-preprocessed-square-images.