I need to do some augmentation for my training images for a neural networks.
The problem is that even when loading batches in parallel, the augmentation is taking longer to perform than the network training.

The problem is in the perspective transforms I'm applying.
Both cv2.warpPerspective and torchvision.transforms.functional.perspective (with PIL images) are taking roughly the same time.

But both of them do it image by images (which seems very inefficient to me).

So, what are the best (fastest and batch-wise) ways of performing perspective transformation?

  • I think of doing it directly with PyTorch functions, but I don't know the algorithm. (Accepting a good algorithm as answer)
  • Any other package that can do it faster?
  • $\begingroup$ Are you saying you're performing augmentation manually? $\endgroup$ Commented Dec 3, 2019 at 12:17
  • $\begingroup$ It's a possibility, as long as it's faster than cv2. $\endgroup$ Commented Dec 3, 2019 at 12:50
  • $\begingroup$ Please note: maintenance > performance. An hour of AI engineer time is worth dozens of hours of GPU rental. $\endgroup$ Commented Dec 3, 2019 at 12:53
  • $\begingroup$ I meant: are you performing augmentation manually with e.g. opencv instead of existing solutions? $\endgroup$ Commented Dec 3, 2019 at 12:55
  • $\begingroup$ Yes I am. I'm an independent researcher looking for faster results. $\endgroup$ Commented Dec 3, 2019 at 13:03

1 Answer 1


Image augmentations heavily relies on your DataGenerator and DataLoader design, mostly along with the hardware resources that you are using. Apart from that, here is a quick comparison chart to help you with the transformations along with the libraries links.

The numbers represent the number of images it processes per second.

enter image description here

Here are the links to all the required libraries:

  1. Albumentations
  2. Imgaug
  3. Augmentor
  4. SOLT

Ref: Albumentations benchmark results

  • $\begingroup$ This might be a very good tool, but if the source code for the perspective transform is here, then it uses cv2.warpPerspective, which is the same thing I use. github.com/aleju/imgaug/blob/master/imgaug/augmenters/… $\endgroup$ Commented Dec 3, 2019 at 13:01
  • $\begingroup$ Yes, you are absolutely correct. Could you elaborate on image size and process pipeline you have created? I'll try to look into it. $\endgroup$
    – thanatoz
    Commented Dec 6, 2019 at 5:29
  • $\begingroup$ Variable image sizes, loop: cv2.open, cv2.resize(256), cv2.warpPerspective, np.array on the list, multiplications, additions, power. $\endgroup$ Commented Dec 6, 2019 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.