Neural Network predicting Fourier Coef for Segmentation - Help for french beginner

Thomas_User: <p>Hi everybody,</p>
<p>I’m trying to develop a neural network in charge of predicting Fourier’s coefficients of a mask from an image. Then I use this coefficients to reconstruct a mask by convulving a gaussian over predicted points.</p>
<p>My implementation of these functions looks like :</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/b/0/b07dcd509373ff58148115206ec53f8bf16b1693.png" data-download-href="https://discuss.pytorch.org/uploads/default/b07dcd509373ff58148115206ec53f8bf16b1693" title="Capture_transform_to_mask"><img src="https://discuss.pytorch.org/uploads/default/original/3X/b/0/b07dcd509373ff58148115206ec53f8bf16b1693.png" alt="Capture_transform_to_mask" data-base62-sha1="pbjyZpJXpeIjDnUZJcwZxBx41iz" width="568" height="500" data-dominant-color="EDEFEE"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Capture_transform_to_mask</span><span class="informations">788×693 21.9 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/0/1/01da64c2c1351db71795cac87fe4235992570cf0.png" data-download-href="https://discuss.pytorch.org/uploads/default/01da64c2c1351db71795cac87fe4235992570cf0" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/0/1/01da64c2c1351db71795cac87fe4235992570cf0_2_690x317.png" alt="image" data-base62-sha1="gonMx3UI4CDmBBE2e9cNkN4OXK" width="690" height="317" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/0/1/01da64c2c1351db71795cac87fe4235992570cf0_2_690x317.png, https://discuss.pytorch.org/uploads/default/optimized/3X/0/1/01da64c2c1351db71795cac87fe4235992570cf0_2_1035x475.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/0/1/01da64c2c1351db71795cac87fe4235992570cf0_2_1380x634.png 2x" data-dominant-color="F1F2F1"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1446×665 42 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>My neural network is created using this function :</p>
<p><img src="https://discuss.pytorch.org/uploads/default/original/3X/a/b/ab3396549ff02eb86aa3cec4daf090837aaba64a.png" alt="Capture_nn" data-base62-sha1="oqwaHnnFltmcBLd0d2Y49SKIbWi" width="650" height="258"></p>
<p>All these functions seems to work correctly</p>
<p>Next, I train my model using this function :</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/0/f/0fcf31a5fd435c6df738aa7d37e35947f1bf5ec4.png" data-download-href="https://discuss.pytorch.org/uploads/default/0fcf31a5fd435c6df738aa7d37e35947f1bf5ec4" title="Capture_train"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/0/f/0fcf31a5fd435c6df738aa7d37e35947f1bf5ec4_2_690x310.png" alt="Capture_train" data-base62-sha1="2fR4wHCSXdDlg2QNBjDsIxDs6SE" width="690" height="310" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/0/f/0fcf31a5fd435c6df738aa7d37e35947f1bf5ec4_2_690x310.png, https://discuss.pytorch.org/uploads/default/optimized/3X/0/f/0fcf31a5fd435c6df738aa7d37e35947f1bf5ec4_2_1035x465.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/0/f/0fcf31a5fd435c6df738aa7d37e35947f1bf5ec4_2_1380x620.png 2x" data-dominant-color="F2F2F2"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Capture_train</span><span class="informations">1439×647 35.6 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>and these parameters :</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/2/5/257d9957864725a0368298cb0f83386a162a913b.png" data-download-href="https://discuss.pytorch.org/uploads/default/257d9957864725a0368298cb0f83386a162a913b" title="Capture_train2"><img src="https://discuss.pytorch.org/uploads/default/original/3X/2/5/257d9957864725a0368298cb0f83386a162a913b.png" alt="Capture_train2" data-base62-sha1="5lELbiTToKK8mgyOnqhMUSlcaVl" width="690" height="133" data-dominant-color="F0F0F0"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Capture_train2</span><span class="informations">1389×269 11.2 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>But the problem is, it doesn’t work <img src="https://discuss.pytorch.org/images/emoji/apple/cry.png?v=12" title=":cry:" class="emoji" alt=":cry:" loading="lazy" width="20" height="20"><br>
The loss doesn’t decrease, and I didn’t find what.<br>
I’ve tried with different epoch, batch, LR and nothing solves the problem</p>
<p>Can someone have an idea ?</p>
<p>Thank you for all,<br>
A beginner with love</p>

ptrblck: <p>I cannot read the code on my phone since you’ve posted it via screenshots instead of formatted code snippets.<br>
In any case, you could try to overfit a small dataset (e.g. just 10 samples) first to make sure your model architecture is capable of doing so and no other errors are in your training code.</p>

Thomas_User: <p>Hi ptrblck,</p>
<p>thanks for your answer and sorry for format’s images I’ve posted.<br>
I’ve already tried to overfit it, and it doesn’t work.<br>
So I tried with different implementation and formula … and it works ! I think problem in the code I posted was in relation with the device, which was not the same for all variables I used</p>