Why set random seed for data augumentation? If I did not, the loss jumped by 1000+ after one epoch in SSD box detction

7029279: <p>I already solved this problem code wise, but I don’t know why what I did worked and want an explanation.</p>
<p>I was doing SSD bounding box detection and loss was okay in the first epoch. Then in the second epoch, it suddenly jumped to 5000-10000 range. This loss jump was coming from my loss function for the location of bounding box, meaning x y coordinates of where the object is; loss function for labeling, classifying the class of the object being detected was okay, going down gradually as expected<br>
I figured out that if I don’t do data augmentations like random flip, random crop, random hue change and stuff of those sorts in my data loader, the loss for xy coordinates doesn’t go crazy. Then I set the random seed and enabled data augmentation, and it also worked fine and loss was stable.</p>
<pre><code class="lang-auto">torch.manual_seed(1234)
np.random.seed(1234)
random.seed(1234)
</code></pre>
<p>Could anyone explain to me what is going on?</p>

ptrblck: <p>What happens, if you change the seed to another number?<br>
I assume you got lucky with this seed and the training might be generally unstable, which is a bad sign. <img src="https://discuss.pytorch.org/images/emoji/apple/confused.png?v=9" title=":confused:" class="emoji" alt=":confused:"></p>

7029279: <aside class="quote no-group" data-username="ptrblck" data-post="2" data-topic="78996">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/48/1823_2.png" class="avatar"> ptrblck:</div>
<blockquote>
<p>What happens, if you change the seed to another number?</p>
</blockquote>
</aside>
<p>Thank you so much for your reply.<br>
I changed the seed from 1234 to 12345 and it is working just as fine.<br>
Below is the loss at the beginning of the 2nd epoch, before, meaning before setting seed values, it was in the range of 5000 to 10000. Now, it is slightly below the loss for the first epoch, which is exactly what I expect it to be.<br>
I guess setting any kind of seed number is important for data augmentation that uses random number generator. I am not quite sure why.</p>
<p><img src="https://discuss.pytorch.org/uploads/default/original/3X/3/7/376877aa8f31166ec65a40fd9feedf7d9f105386.png" alt="image" data-base62-sha1="7Ua52H3kC9mTRf1aVMaidC0RPRc" width="613" height="87"></p>

ptrblck: <p>Thanks for the update!<br>
It would still be interesting to see a few runs for different seeds.</p>

7029279: <aside class="quote no-group" data-username="ptrblck" data-post="4" data-topic="78996">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/48/1823_2.png" class="avatar"> ptrblck:</div>
<blockquote>
<p>It would still be interesting to see a few runs for different seeds.</p>
</blockquote>
</aside>
<p>I did another random number and it was very stable learning curve and detection was not that terrible although I think I need a few more epochs.<br>
What I dont understand is that the loss jumped from the second epoch, when I did not set the seed, but was rather stable in the first round? Why would this be?</p>
<pre><code class="lang-auto">torch.manual_seed(12241251)
np.random.seed(12241251)
random.seed(12241251)
</code></pre>
<p><img src="https://discuss.pytorch.org/uploads/default/original/3X/f/0/f0a83aaafe552f019d0420647d7b7e386a0fefcd.png" alt="image" data-base62-sha1="ykX1nvMNq6D89s5woBKqGFVar37" width="386" height="265"><br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/c/8/c8a9c7e33fdf7394a3b2843980cdf7dd15ddce7a.jpeg" alt="image" data-base62-sha1="sD9fmxM8LcZH4x3vmUWzayY6QT8" width="598" height="453"></p>

ptrblck: <aside class="quote no-group" data-username="7029279" data-post="5" data-topic="78996">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/7029279/48/23087_2.png" class="avatar"> 7029279:</div>
<blockquote>
<p>Why would this be?</p>
</blockquote>
</aside>
<p>Different seeds might create “lucky” or “bad” runs.<br>
Usually, it’s a bad sign if only a specific seed is letting your model train properly while others fail.</p>
<p>If you are seeing the loss explosion for all (or the majority) of vanilla runs, and observe proper training for seeding the code with random values, this might be some bug I cannot explain, and we would need to dig into it.</p>
<p>Could you create an executable code snippet, which would demonstrate the observed behavior?</p>

7029279: <aside class="quote no-group" data-username="ptrblck" data-post="6" data-topic="78996">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/48/1823_2.png" class="avatar"> ptrblck:</div>
<blockquote>
<p>Could you create an executable code snippet, which would demonstrate the observed behavior?</p>
</blockquote>
</aside>
<p>I am sorry for the late response.<br>
I found some questionable codes in my program, and I am now looking into it. But I am thinking the weird behavior might be due to this issue.<br>
However, thank you for your engagement.</p>