att_a_ = (att_a * 2 - 1) * args.thres_int if args.b_distribution == 'none': att_b_ = (att_b * 2 - 1) * args.thres_int if args.b_distribution == 'uniform': att_b_ = (att_b * 2 - 1) * \ torch.rand_like(att_b) * \ (2 * args.thres_int) if args.b_distribution == 'truncated_normal': att_b_ = (att_b * 2 - 1) * \ (torch.fmod(torch.randn_like(att_b), 2) + 2) / 4.0 * \ (2 * args.thres_int) if (it+1) % (args.n_d+1) != 0: errD = attgan.trainD(img_a, att_a, att_a_, att_b, att_b_) add_scalar_dict(writer, errD, it+1, 'D') else: errG = attgan.trainG(img_a, att_a, att_a_, att_b, att_b_) add_scalar_dict(writer, errG, it+1, 'G') progressbar.say(epoch=epoch, iter=it+1, d_loss=errD['d_loss'], g_loss=errG['g_loss']) if (it+1) % args.save_interval == 0: # To save storage space, I only checkpoint the weights of G. # If you'd like to keep weights of G, D, optim_G, optim_D, # please use save() instead of saveG(). attgan.saveG(os.path.join( 'output', args.experiment_name, 'checkpoint', 'weights.{:d}.pth'.format(epoch) )) 我这里面有模型保存的命令么
时间: 2024-02-14 13:30:09 浏览: 92
ATT7022_C51接收.rar_*7022*_ATT7022_ATT7022读ID_SPI_Att7022_att7022驱
是的,您的代码中包含了模型保存的命令。在代码中,使用了`attgan.saveG()`函数来保存生成器型的权重。
具体来说,在每个`args.save_interval`步骤处,通过调用`attgan.saveG()`函数来保存生成器模型的权重。这个函数将生成器的权重保存到指定路径中的.pth文件中。
以下是您代码中模型保存的部分:
```python
if (it+1) % args.save_interval == 0:
attgan.saveG(os.path.join(
'output', args.experiment_name, 'checkpoint', 'weights.{:d}.pth'.format(epoch)
))
```
上述代码段将生成器模型的权重保存到指定路径中。请确保在运行代码之前创建好相应的目录结构,以便能够成功保存模型权重。
阅读全文