After loading weights to GAN generator, the result doesn't seem like generating from learnt weights but random noise

username: shania3322
cooked: <p>Hey guys,</p>
<p>I was implement a GAN network from online (followed by this github: <a href="https://github.com/AaronLeong/BigGAN-pytorch" class="inline-onebox" rel="noopener nofollow ugc">GitHub - sxhxliang/BigGAN-pytorch: Pytorch implementation of LARGE SCALE GAN TRAINING FOR HIGH FIDELITY NATURAL IMAGE SYNTHESIS (BigGAN)</a>).</p>
<p>The test file is missing so I wrote it by myself.  The code ran successfully but the result didn’t show that the image is generated from learnt weights, but looks like generating from initial random noise. The code is as follows</p>
<pre><code class="lang-auto">model = Generator(z_dim,n_class,chn)
checkpoint = torch.load('./model/faces/241280_G.pth', map_location = str(device))
model.load_state_dict(checkpoint,strict=False)
model.to(device)
model.float()
model.eval()

def label_sampel():
    label = torch.LongTensor(batch_size, 1).random_()%n_class
    one_hot= torch.zeros(batch_size, n_class).scatter_(1, label, 1)
    print(device)
    return label.squeeze(1).to(device), one_hot.to(device)       

z = torch.randn(batch_size, z_dim).to(device)
z_class, z_class_one_hot = label_sampel()
fake_images = model(z, z_class_one_hot)
save_image(denorm(fake_images.data), os.path.join(path, '1_generated.png'))
</code></pre>
<p>These are face image samples that generated during training phase.<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/2X/a/a8af66d8583f312bd9087e341f5f756d9e3bea01.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/a8af66d8583f312bd9087e341f5f756d9e3bea01" title="42900_fake"><img src="https://discuss.pytorch.org/uploads/default/optimized/2X/a/a8af66d8583f312bd9087e341f5f756d9e3bea01_2_690x345.jpeg" alt="42900_fake" data-base62-sha1="o4g0IjiaqdKBK5oP9qcu2MSz24V" width="690" height="345" srcset="https://discuss.pytorch.org/uploads/default/optimized/2X/a/a8af66d8583f312bd9087e341f5f756d9e3bea01_2_690x345.jpeg, https://discuss.pytorch.org/uploads/default/optimized/2X/a/a8af66d8583f312bd9087e341f5f756d9e3bea01_2_1035x517.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/original/2X/a/a8af66d8583f312bd9087e341f5f756d9e3bea01.jpeg 2x" data-dominant-color="695044"><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">42900_fake</span><span class="informations">1042×522 263 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 one is the image that I tried generate from trained generator via loading generator’s weights file.<br>
<img src="https://discuss.pytorch.org/uploads/default/original/2X/f/ff6cbda3f793251d170c63ce74c02a351c5e9a09.png" alt="1_generated" data-base62-sha1="ArAJk23QustumuYAlyDujkCTZpv" width="128" height="128"></p>
<p>Can some one help with it?<br>
Thanks in advance.</p>

username: ptrblck
cooked: <p>Did the training run generate the first picture?<br>
If so, could you store this random input tensor for the sake of debugging, and use it for the test case?</p>

username: shania3322
cooked: <p>Hey!<br>
Yeah, the first picture is the sample generating during training with batch size 32.<br>
As you suggested, I reran the training and stored the input which is the random noise data corresponding to that iteration.<br>
It worked when I redo everything.</p>
<p>And then I figured out the weight file were actually loaded. Inputs were fine too. When input went through the model build with weights, it didn’t generate a face-like image. I figured that something wrong with weight file.</p>
<p>What I did before is that I copied the weight file from a locked folder(has to use sudo to manipulate the folder) to another normal folder. And load weight file from there. I guess something got lost while I move the weight file. It worked if I keep them in original folder which created during initialization.</p>

username: shania3322
cooked: <p>And I removed model.eval() but set requires_grad = False for input.</p>

username: shania3322
cooked: <p>Hey, I think I’m wrong.</p>
<p>Actually the when I did it again, the training was finished. And the first time the training was interrupted and did complete.</p>
<p>I still don’t know exactly why is that. The code used torch.nn.DataParallel for both Generator and Discriminator during training. And I loaded the weights to gpu while testing.</p>
<p>How do I check if weights are loaded?</p>