Skip to main content

A library which turns torchvision transformations invertible and replayable.

Project description

invertransforms

Build Status Code Coverage PyPI

A library which turns torchvision transformations invertible and replayable.

Installation

pip install invertransforms

Usage

Simply replace previous torchvision import statements and enjoy the new features.

# from torchvision import transforms as T
import invertransforms as T

transform = T.Compose([
  T.RandomCrop(size=256),
  T.ToTensor(),
])

img_tensor = transform(img)

# invert
img_again = transform.invert(img_tensor)

# replay
img_tensor2 = transform.replay(img2)

# track
for i in range(n):
    img_tensor_i = transform.track(img_i)
    # ...
inverse_tf = transform.get_inverse(j)  # or transform[j]
img_j = inverse_tf(img_tensor_j)

All transformations have an inverse transformation attached to it.

inv_transform = transform.inverse()
img_inv = inv_transform(img)

Notes:

If a transformation is random, it is necessary to apply it once before calling invert or inverse(). Otherwise it will raise InvertibleError. On the otherhand, replay can be called before, it will simply set the randomness on its first call.

One can create its own invertible transforms either by using the practical Lambda class function or by extending the Invertible class available in the invertransforms.lib module.

Documentation

The library's documentation contains the full list of transformations which includes all the ones from torchvision and more.

Use Cases

This library can be particularly useful in following situations:

  • Reverting a NN-model output in order to stack predictions

  • Applying the same (random) transformations the same way on different inputs

Features

  • Invert any transformations, even random ones

  • Replay any transformations, even random ones

  • Track all transformations to invert them long after

  • All classes extend its torchvision transformation equivalent class. This means, you can just replace your previous torchvision import statements and it will not break your code.

  • Extensive unit testing (100% coverage, be safe, hopefully)

Requirements

python>=3.6

torch>=1.2.0
torchvision>=0.4.0

Future Improvements

  • [WIP] Extend the number of tranformations (e.g. random rotation and cropping (within the rotated area))

  • Make the transformations on tensors directly (data augmentation/transformation on GPU)

Contribute

You found a bug, think a feature is missing or just want to help ?

Please feel free to open an issue, pull request or contact me mail@gregunz.io

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

invertransforms-0.2.1.tar.gz (14.9 kB view details)

Uploaded Source

File details

Details for the file invertransforms-0.2.1.tar.gz.

File metadata

  • Download URL: invertransforms-0.2.1.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.8

File hashes

Hashes for invertransforms-0.2.1.tar.gz
Algorithm Hash digest
SHA256 f2d5f761a435ff1d2185fb550ae61ade76d4519820c53fbd24ff332eca71181e
MD5 a44265508ef11f7bf2f79db67ba0f3e9
BLAKE2b-256 25d4a84dde03176e0d3ce2911c20d49f6a2bf7630953c83fcec81ea27fba3c25

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page