bentrevett / pytorch-image-classification

Tutorials on how to implement a few key architectures for image classification using PyTorch and TorchVision.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Remark : Reproducibility is broken.

Tikquuss opened this issue · comments

In notebooks you say: "To ensure we get reproducible results we set the random seed for Python, Numpy and PyTorch.".
But if you do it in a cell of a notebook, it is only valid for that cell, and therefore reproducibility is not guaranteed.
Take a look at this capture.
bad_random_seed

@Tikquuss Sorry for the late reply. Just getting back from my Christmas break.

Isn't this the expected result? The way I thought it worked is that once you set a random seed then all calls to random.random() (or a similar function) will still give different results, but if I set the seed again and then called random.random() I'll get the same results as when I first called them.

>>> import random
>>> random.seed(1)
>>> random.random() # these three calls should give different "random" results
0.13436424411240122
>>> random.random()
0.8474337369372327
>>> random.random()
0.763774618976614
>>> random.seed(1) # re-seed here so the next three calls give the same "random" results as above
>>> random.random() # which they do
0.13436424411240122
>>> random.random()
0.8474337369372327
>>> random.random()
0.763774618976614

I might not understand how randomness works in Python, please let me know where my mistake is.