Open dhorka opened 5 years ago
import imgaug as ia
print(ia.current_random_state())
this should get you the current global random state (or access directly ia.CURRENT_RANDOM_STATE
). Note that each augmenter has its own random state attribute, which usually points towards the global random state, but it can also be an independent random state. That is the case e.g. when reseed() or localize_random_state() or to_deterministic() was called on the augmenter or one if its parents.
I see. Thanks! Another question, there is a setter for the random state? I mean once I have recovered the state if I want to set this state in another run. Is there a function to do it or I need do something like ia.CURRENT_RANDOM_STATE = SAVED_RANDOM_STAT ?
You will have to set ia.CURRENT_RANDOM_STATE
, there is no function for that.
To change augmenter-specific random states, just change augmenter.random_state = <random state>
.
Hi, I can't set a random state. Versions: Python : 3.7.1 Ubuntu 18.04.2 LTS imgaug : 0.3.0 pillow: 6.2.0 numpy: 1.17.2
Here is what I've tried:
import imgaug as ia
from imgaug import augmenters as iaa
import numpy as np
import cv2
ia.seed(1)
#ia.random.seed(13)
#np.random.seed(13)
#np.random.RandomState(seed=0)
#np.random.RandomState.set_state(1)
img = cv2.imread("plane.png")
images = [img for _ in range(10)]
fog = iaa.weather.Fog(name="sinir", deterministic=True, random_state=1)
img_fogg = fog.augment_images(images)
for i in range(10):
cv2.imwrite("output/fog_"+str(i)+"_planes.png", img_fogg[i])
Is there a problem? What should I try for reproducibility?
What do you mean with "I can't set a random state"? Do you get an error? The loop is expected to produce different images as every example in a batch gets different random samples. They are just derived from the initial seed. If you want to produce many times the exactly same augmentation, then use something like
fog = iaa.Fog()
fog = fog.to_deterministic()
for i in range(10):
cv2.imwrite(<filepath>, fog(image=images[i]))
Note that fog
is called once per example. The random state is automatically reset after each call due to fog
running in deterministic mode.
Oh, thank you very much!
11 Eki 2019 Cum 19:47 tarihinde Alexander Jung notifications@github.com şunu yazdı:
What do you mean with "I can't set a random state"? Do you get an error? The loop is expected to produce different images as every example in a batch gets different random samples. They are just derived from the initial seed. If you want to produce many times the exactly same augmentation, then use something like
fog = iaa.Fog() fog = fog.to_deterministic()for i in range(10): cv2.imwrite(
, fog(image=images[i])) Note that fog is called once per example. The random state is automatically reset after each call due to fog running in deterministic mode.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/aleju/imgaug/issues/245?email_source=notifications&email_token=AFQOSDG37GVOCZVAZWERSF3QOCU23A5CNFSM4GS5USQ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBASGWY#issuecomment-541139803, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFQOSDDNRRJWOQ5RJCGPLCLQOCU23ANCNFSM4GS5USQQ .
Hi,
I would like to know if it is possible to recover the random number generator state of the library. I saw there is a method to choice the seed at the beggining but I do not find the method to recover the current state of the random number generator. Is this function currently implemented?
Thanks,