Data augmentation for multiple images

Jaturong: <p>I’m beginner for Pytorch. I want to increase the number of datasets (data augmentation).<br>
I have two images (cat_1 and cat_2) in folder and I want to use <code>albumentation</code> to increase the number of images as follows:</p>
<pre><code class="lang-auto">import cv2
import torch
import albumentations as A
import numpy as np
import matplotlib.pyplot as plt
import os
from os import listdir
from os.path import join, isfile
from torchvision.utils import save_image

# Read files from Directory
Dir_img = '/content/drive/MyDrive/Cat_Dog'
files = os.listdir(Dir_img)
print(files) # ['cat_1.jpg', 'cat_2.jpg']
</code></pre>
<p>After that, I use <code>OpenCV</code> to read images from Dir_img and keep array of each image into list as follows:</p>
<pre><code class="lang-auto">dataset = [] # &lt;class 'list'&gt; In list consist of array of each image 
             # len(dataset) = 2

for img in files:
  img_ = cv2.imread(os.path.join(Dir_img,img), cv2.IMREAD_UNCHANGED) # default BGR
  Org_ = cv2.cvtColor(img_, cv2.COLOR_BGR2RGB) # Convert BGR -&gt; RGB
  dataset.append(Org_)

  # cat_1: dataset[0].shape = (666, 1000, 3)
  # cat_2: dataset[1].shape = (825, 1100, 3) 
</code></pre>
<p>Next, I defined an <code>augmentation pipeline (multiple files)</code> as follows:</p>
<pre><code class="lang-auto">TRANSFORM = A.Compose([
    A.Blur(p = 0.5, blur_limit = (3, 7)),  
    A.RandomBrightnessContrast(p = 0.5, brightness_limit = 1, contrast_limit = 1)
])
</code></pre>
<p>After that, I will pass all images to the augmentation pipeline and receive augmented images.</p>
<pre><code class="lang-auto">for IMG in dataset: # IMG is &lt;class 'numpy.ndarray'&gt;
  MY_TRANSFORMED = TRANSFORM(image=IMG)  #&lt;class 'dict'&gt;

  #Convert 'dict' to 'numpy.array'
  MY_TRANSFORMED_IMAGE = MY_TRANSFORMED['image']  # &lt;class 'numpy.ndarray'&gt;
  
  MY_TRANSFORMED_IMAGE_1 = TRANSFORM(image=IMG)['image']
  MY_TRANSFORMED_IMAGE_2 = TRANSFORM(image=IMG)['image']
  MY_TRANSFORMED_IMAGE_3 = TRANSFORM(image=IMG)['image']
</code></pre>
<p>From above code, I received a total of 3 images of different <code>cat_2</code>. <strong>But I think the resulting image should be of a <code>cat_1</code>.</strong></p>
<p><strong>I have questions as follows:</strong></p>
<ol>
<li>Every time, I run <code>TRANSFORM</code>. I receive a different image every time. <strong>Is there a way to get me the same results every time?</strong>
</li>
<li><strong>Why haven’t I received an image of a <code>cat_1</code>?</strong></li>
<li>If I want <strong>1 original images</strong> (<code>cat_1</code> and <code>cat_2</code>) to do <strong>10 different data augmentations,</strong> I can use a <code>for loop</code> ?</li>
</ol>
<p>I’ve tried to find document from various sources, but I’m not getting the answer I’m wondering.</p>

ptrblck: <ol>
<li>
<p>If you are using random transformations you would need to seed the corresponding library.</p>
</li>
<li>
<p>Are you checking the last output after the <code>for</code> loop was executed? If so, note that the second iteration will transform <code>cat_2</code> while the first iteration should be transforming <code>cat_1</code>. Add a debug <code>print</code> statement to check which image is currently being transformed inside the loop.</p>
</li>
<li>
<p>Yes.</p>
</li>
</ol>