aleju / imgaug

Image augmentation for machine learning experiments.
http://imgaug.readthedocs.io
MIT License
14.42k stars 2.44k forks source link

How to do deterministic inside batch #851

Open Mactarvish opened 6 months ago

Mactarvish commented 6 months ago

Seems to_deterministic uses single random seed among multi-times call, but NOT inside a batch:

import time
import random
import os
import glob
import cv2
import numpy as np
import imgaug as ia
import imgaug.augmenters as iaa

if __name__ == "__main__":
    iapipline = \
    iaa.Sequential([
        iaa.Resize((0.8, 1.2), interpolation="linear"),
        iaa.CenterPadToFixedSize(224, 128),
        iaa.CenterCropToFixedSize(224, 128)
    ]).to_deterministic()

    src_image_paths = glob.glob(os.path.join("pgs/cases/*.jpg"))
    src_image_nps = [cv2.imread(e) for e in src_image_paths]

    src_image_nps = np.stack(src_image_nps)

    # every image in src_image_nps will use different random
    rr =  iapipline(images=src_image_nps)

    rr = []
    # only in this way will every image use the same random
    for i in range(len(src_image_nps)):
        rr.append(iapipline(image=src_image_nps[i]))

How to set the same random inside a batch?