MCPcopy Create free account
hub / github.com/KeepTryingTo/Pytorch-GAN / save_epoch_image

Function save_epoch_image

Adversarial_AutoEncoder/utils.py:15–39  ·  view source on GitHub ↗
(model1,model2,filename,val_loader,epoch)

Source from the content-addressed store, hash-verified

13from torchvision.utils import save_image
14
15def save_epoch_image(model1,model2,filename,val_loader,epoch):
16 imgs = val_loader
17 encoder_Img = model1(imgs)
18 decoder_Img = model2(encoder_Img).detach().cpu().numpy()
19 imgs = np.squeeze(val_loader.detach().cpu().numpy())
20 fig = plt.figure(figsize=(4,4))
21 result = np.squeeze(decoder_Img)
22
23 #save encoder and decoder image
24 for i in range(config.BATCH_SIZE):
25 plt.subplot(4,4,i + 1)
26 plt.imshow((result[i] + 1) / 2)
27 plt.axis("off")
28 plt.savefig(os.path.join(filename,f"{epoch}_AE.png"))
29 plt.close('all') # 避免内存泄漏
30
31 fig = plt.figure(figsize=(4, 4))
32 #save original images
33 for i in range(config.BATCH_SIZE):
34 plt.subplot(4,4,i + 1)
35 plt.imshow((imgs[i] + 1) / 2)
36 plt.axis("off")
37
38 plt.savefig(os.path.join(filename,f"{epoch}_input.png"))
39 plt.close('all') # 避免内存泄漏
40
41
42def draw(loss,epochs):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected