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

Function save_some_examples

pix2pix/utils.py:11–29  ·  view source on GitHub ↗

:param gen: 生成模型 :param val_loader:加载的验证集数据集 :param epoch: 迭代次数 :param folder: 保存文件路径 :return:

(gen, val_loader, epoch, folder)

Source from the content-addressed store, hash-verified

9from torchvision.utils import save_image
10
11def save_some_examples(gen, val_loader, epoch, folder):
12 """
13 :param gen: 生成模型
14 :param val_loader:加载的验证集数据集
15 :param epoch: 迭代次数
16 :param folder: 保存文件路径
17 :return:
18 """
19 x, y = next(iter(val_loader))
20 x, y = x.to(config.DEVICE), y.to(config.DEVICE)
21 gen.eval()
22 with torch.no_grad():
23 y_fake = gen(x)
24 y_fake = y_fake * 0.5 + 0.5 # remove normalization#
25 save_image(y_fake, folder + f"/y_gen_{epoch}.png")
26 save_image(x * 0.5 + 0.5, folder + f"/input_{epoch}.png")
27 if epoch == 1:
28 save_image(y * 0.5 + 0.5, folder + f"/label_{epoch}.png")
29 gen.train()
30
31
32def save_checkpoint(model, optimizer, filename="my_checkpoint.pth.tar"):

Callers 1

mainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected