Skip to content

jundanl/joint-transforms-for-torchvision

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

joint-transforms-for-torchvision

First of all, thanks torchvision_paired_transforms a lot. This project is based on it, but there are some differences.

Abstract

  1. This project modifies transforms.py from torchvision 0.2.1, in order to do the same fixed(or random) transformation on an arbitrary number of images simultaneously
  2. Features:
    • Accept an arbitrary number of images as input
    • Do the same transformation on all the input. Don't distinguish them between input image and target image, just treat them the same.
    • Don't change the interface when there is only one input image. That means you don't need to change your code which once used transforms.py from torchvision.
  3. Till now, these classes have been modified to accept multiple images as input
Compose, ToTensor, ToPILImage, Resize, CenterCrop, 
RandomCrop, RandomHorizontalFlip, RandomVerticalFlip, RandomResizedCrop, RandomRotation
ColorJitter, Grayscale, RandomGrayscale

How to use

  1. Change import

    Replace

    import torchvision.transforms as transforms

    by

    import joint_transforms_tv021 as transforms
  2. Do joint transformation

    a. Compose

        co_transforms = transforms.Compose((
            transforms.Resize(250, interpolation=Image.BILINEAR),
            transforms.RandomHorizontalFlip(),
            transforms.RandomRotation(degrees=5.0, resample=Image.BILINEAR),
            transforms.ToTensor(),
            ))

    b. single input image

    input_im = co_transforms(input_im)

    or

    input_im = transforms.ToTensor()(input_im)
    ...

    c. multiple input images

    input_im, s_im, r_im, target_depth_im = co_transforms(input_im, s_im, r_im, target_depth_im)

    or

    input_im, s_im, r_im, target_depth_im = transforms.ToTensor()(input_im, s_im, r_im, target_depth_im)
    ...

Notification

  1. Only a few transformations have already been modified till now.
  2. If your input images have different channels, you'd better look for the source code to find out what joint transformations actually do, especially for some transformations aiming at changing image color, e.g. Grayscale()

Future

  1. If you find any bug, please tell me.
  2. If you know how to make the code seem more elegant, please tell me.
  3. If you modify the remain classes, please send me a pull request.
  4. I hope the code can be matained until torchvision release joint transformation.

About

Modify transforms.py from torchvision, in order to do the same fixed or random transformation on multiple images simultaneously for data augmentation

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages