(model,filename,val_loader,epoch)
| 13 | from torchvision.utils import save_image |
| 14 | |
| 15 | def 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 | |
| 41 | def draw(loss,epochs): |
nothing calls this directly
no outgoing calls
no test coverage detected