The fastest way to save multiple images from torch tensor

Hi, I’m trying to save multiple images (number of batch_size) from tensors.

Let’s say, we want to add an adversarial noise on each image.

The most efficient way I can think of is that

  1. load images of batch size
  2. calculate adversarial noise and add them --> which makes Tensor([B, C, W, H])
  3. using for loop to save each image from the tensor.

Is there a faster or more ‘data-parallel’ way to save images?

1 Like

I recommend you to use imageio which is a very fast and nice library together with multiprocessing.


I am using matplot pyplot, I am not sure what I am doing wrong. it always print the first image. Any help?

for t in range(0,batch_size):
    a = image[t].cpu().numpy()