Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to do deterministic inside batch #851

Open
Mactarvish opened this issue May 20, 2024 · 0 comments
Open

How to do deterministic inside batch #851

Mactarvish opened this issue May 20, 2024 · 0 comments

Comments

@Mactarvish
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant