DCGAN - Getting Not Implemented Exception

ArshadIram: <p>I am following this document to implement DC GAN <a href="https://pytorch.org/tutorials/beginner/dcgan_faces_tutorial.html#generative-adversarial-networks" class="inline-onebox" rel="noopener nofollow ugc">DCGAN Tutorial — PyTorch Tutorials 2.2.0+cu121 documentation</a></p>
<p>However, I am not using num_workers = 2. I am only using Default workers and device is cuda:0.</p>
<p>on training the generator and discriminators I am getting this error:</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/0/a/0ae2f79a349bc0bf9b87d42178f7f488ba6c870f.png" data-download-href="https://discuss.pytorch.org/uploads/default/0ae2f79a349bc0bf9b87d42178f7f488ba6c870f" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/0/a/0ae2f79a349bc0bf9b87d42178f7f488ba6c870f_2_690x156.png" alt="image" data-base62-sha1="1yj34YkBP24ddylC9tDl17uztwP" width="690" height="156" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/0/a/0ae2f79a349bc0bf9b87d42178f7f488ba6c870f_2_690x156.png, https://discuss.pytorch.org/uploads/default/optimized/3X/0/a/0ae2f79a349bc0bf9b87d42178f7f488ba6c870f_2_1035x234.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/0/a/0ae2f79a349bc0bf9b87d42178f7f488ba6c870f.png 2x" data-dominant-color="303034"><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">1183×268 41.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>Here is the code line:</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/9/4/94c95b6f30a91fd720a46a7793118fa1e8a149ab.png" data-download-href="https://discuss.pytorch.org/uploads/default/94c95b6f30a91fd720a46a7793118fa1e8a149ab" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/9/4/94c95b6f30a91fd720a46a7793118fa1e8a149ab.png" alt="image" data-base62-sha1="lee4qjXmf0gVlMWAyxFe4WioLnZ" width="690" height="149" data-dominant-color="392A2A"><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">765×166 14.5 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>This last line is resulted in throwing this exception.</p>
<p>Please help me in solving this exception. Thank you in advance.</p>

ptrblck: <p>The error is raised in the forward pass, as the missing <code>forward</code> method cannot be found.<br>
Could you post the definition of <code>netD</code> so that we could take a look at it?</p>

ArshadIram: <p>Hi, here is the code snippet:</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/d/e/de59cb6668653402a5ec26f878c3a0a5f72c1c8e.png" data-download-href="https://discuss.pytorch.org/uploads/default/de59cb6668653402a5ec26f878c3a0a5f72c1c8e" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/d/e/de59cb6668653402a5ec26f878c3a0a5f72c1c8e_2_690x417.png" alt="image" data-base62-sha1="vJ0nHHlsXo9zcB9Iv8KTDC2Fdgy" width="690" height="417" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/d/e/de59cb6668653402a5ec26f878c3a0a5f72c1c8e_2_690x417.png, https://discuss.pytorch.org/uploads/default/original/3X/d/e/de59cb6668653402a5ec26f878c3a0a5f72c1c8e.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/d/e/de59cb6668653402a5ec26f878c3a0a5f72c1c8e.png 2x" data-dominant-color="2E2E2E"><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">991×599 50 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>please have a look. On the top weights are define and in last two models are defined.</p>

Vrushank98: <p>I guess, In Discriminator class, you have defined your def forward() inside <strong>init</strong>(), it should be outside init function.</p>

ArshadIram: <p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/5/5/552d4a0d656c469a90f57d03541197dc0d9575f7.png" data-download-href="https://discuss.pytorch.org/uploads/default/552d4a0d656c469a90f57d03541197dc0d9575f7" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/5/5/552d4a0d656c469a90f57d03541197dc0d9575f7_2_448x500.png" alt="image" data-base62-sha1="c9vCeXwpWPMQqc36aPlilizNOar" width="448" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/5/5/552d4a0d656c469a90f57d03541197dc0d9575f7_2_448x500.png, https://discuss.pytorch.org/uploads/default/optimized/3X/5/5/552d4a0d656c469a90f57d03541197dc0d9575f7_2_672x750.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/5/5/552d4a0d656c469a90f57d03541197dc0d9575f7.png 2x" data-dominant-color="302F2E"><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">750×837 69 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>Forward function is immediate after the discriminator but it is not inside init () function!</p>

ptrblck: <p>The <code>forward</code> method seems to be outside of the model definition, so you would have to add an indentation.</p>
<p>PS: you can post code snippets by wrapping them into three backticks ```, which makes debugging easier.</p>

Vrushank98: <p>Your forward() method is outside the discriminator class, bring it to the same vertical indent line as the init() method.</p>

ArshadIram: <p>Thank you so much for replies. It is solved.</p>

ArshadIram: <p>There was an indentation problem of forward method. It should be same vertical indent line as the init() method.</p>