:param model: 生成器训练的模型 :param epoch: 迭代次数 :param test_input: 对产生的噪声生成图像 :return:
(model,epoch,test_input)
| 50 | |
| 51 | #绘图函数 |
| 52 | def DrawGen(model,epoch,test_input): |
| 53 | """ |
| 54 | :param model: 生成器训练的模型 |
| 55 | :param epoch: 迭代次数 |
| 56 | :param test_input: 对产生的噪声生成图像 |
| 57 | :return: |
| 58 | """ |
| 59 | result = model(test_input).detach().cpu().numpy() |
| 60 | #将维度为1的进行压缩 |
| 61 | result = np.squeeze(result) |
| 62 | fig = plt.figure(figsize=(4,4)) |
| 63 | for i in range(16): |
| 64 | plt.subplot(4, 4, i + 1) |
| 65 | #由于生成器输出的结果为[-1,1]之间,所以需要转换为[0,1]之间 |
| 66 | plt.imshow((result[i] + 1) / 2) |
| 67 | plt.axis('off') |
| 68 | plt.savefig('images/{}.png'.format(epoch)) |
| 69 | # plt.show() |
| 70 | |
| 71 | |
| 72 | #训练生成器 |