Question regarding np.random.seed(2) in lesson 1 part 1 of the course

in the notebook of the lesson 1 in part 1 (the task of classifying pets) there is a line of code that was written before using ImageDataBunch.from_name_re which i did not understand:

is this a code that i am supposed to understand at this stage of the course ? any simple explanation of what it means ?

Search these forums for np.random.seed, and all will be revealed.

Hi basel hope all is well!

If you go to lesson 2 video at about 24 mins Jeremy talks about validation sets and why when training models using the same validation set is important. This is done using np.random.seed(2) it ensures that same random images are used in the validation set every time.

Cheers mrfabulous1 :smiley::smiley:

1 Like

Hi Basel.
Random numbers are meant to be random and you can take real random numbers from nature.
Computer generated random numbers use a formula to generate the first, second, third etc. The formula (or algorithm) needs a start point so you could use the number of microseconds since 1970 and obviously every time you generated a sequence it would be different. This start point is called the seed. If you want to use the same random sequence to repeat the experiment you would set the seed to the same number. Hence np.random.seed(2). See the other comment for the specific example.
Regards Conwyn

1 Like

but the fact is it is not, every time you refresh it you have different images. correct me if i am wrong

Hi Aamir Hope you are well!

It is my understanding that if you set np.random.seed(42) then as in lesson 2 it means that the same set of images is used in your validation set. if you reset and run it again then then you would get a different set of values. I believe it is this way to make sure once you start a session if you change your model or make some improvements your can ensure that your validation set hasn’t changed and any improvements in learning are due to your other changes.

Cheers mrfabulous1 :smiley::smiley: