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

Function save_epoch_image

Dropout_AutoEncoder/utils.py:15–38  ·  view source on GitHub ↗
(model,filename,val_loader,epoch)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected