Skip to content

Instantly share code, notes, and snippets.

@DanielTakeshi
Last active November 7, 2018 21:14
Show Gist options
  • Save DanielTakeshi/bae674deb74bced22fdc3ca39c4fe3aa to your computer and use it in GitHub Desktop.
Save DanielTakeshi/bae674deb74bced22fdc3ca39c4fe3aa to your computer and use it in GitHub Desktop.
PyTorch transforms. See this for saving images: https://gist.github.com/DanielTakeshi/bbaf432347aafa2e9878e93fd6982fd7
I am testing different PyTorch transforms on my data, and saving sample
images as they are loaded during training. See examples below.
@DanielTakeshi
Copy link
Author

DanielTakeshi commented Nov 7, 2018

transforms.Resize(256)
transforms.RandomResizedCrop(224)

By default, the random resized crop might have an initial crop as small as 8 percent of the original image, as you can see by some of the "zoomed in" stuff. And from the other one we did earlier (the Resize just made this 256x256 here before applying the RandomResizedCrop).

train_0000_success train_0001_success train_0002_success

train_0003_success train_0004_success train_0005_success

train_0006_success train_0007_success train_0008_success

@DanielTakeshi
Copy link
Author

transforms.RandomResizedCrop(224, scale=(0.8, 1.0))

Now we don't do the initial scaling. This is probably better for the data we have, less "zoomed in" stuff.

train_0000_failure train_0001_failure train_0002_failure

train_0003_success train_0004_success train_0005_failure

train_0006_failure train_0007_failure train_0008_failure

@DanielTakeshi
Copy link
Author

175             transforms.RandomResizedCrop(224, scale=(0.8, 1.0))
176             transforms.RandomVerticalFlip()

So when they say vertical flip, that means a flip ABOUT THE HORIZONTAL AXIS. It is more intuitive their way.

TL;DR in my code use the HORIZONTAL TRANSFORM, so we flip about the vertical axis.

train_0000_success train_0001_failure train_0002_success

train_0003_failure train_0004_success train_0005_success

train_0006_success train_0007_success train_0008_failure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment