|
楼主 |
发表于 2024-9-19 00:28:51
|
显示全部楼层
# 重新训练的次数
for i in range(cycles):
# 记录当前时间
iter_time = time.time()
# 使用已选定的SRC和DST样本,重新进行训练,并计算LOSS
# src_loss, dst_loss = self.src_dst_train (target_src, target_src, target_srcm, target_srcm_em, target_dst, target_dst, target_dstm, target_dstm_em)
src_loss, dst_loss = self.src_dst_train (warped_src, target_src, target_srcm, target_srcm_em, warped_dst, target_dst, target_dstm, target_dstm_em)
# 判定是否为,最后一次。是则交由返回进行记录,否则在循环内记录
if i != cycles-1:
# 获取重训练样本的平均LOSS值
losses = ( ('src_loss', np.mean(src_loss) ), ('dst_loss', np.mean(dst_loss) ), )
# 计算本次训练的运算耗时
iter_time = time.time() - iter_time
# 将重训练样本的LOSS值,写入历史记录
self.loss_history.append ( [float(loss[1]) for loss in losses] )
# 更新数据,并输出显示
self.repeated_training(iter_time)
else:
# 如果启用了真实人脸权重,且不是预训练模式
if self.options['true_face_power'] != 0 and not self.pretrain:
# 训练判别器
self.D_train (warped_src, warped_dst)
# 如果启用了GAN权重
if self.gan_power != 0:
# 训练带有SRC和DST的判别器
self.D_src_dst_train (warped_src, target_src, target_srcm, target_srcm_em, warped_dst, target_dst, target_dstm, target_dstm_em)
# 计算本次训练的运算耗时
iter_time = time.time() - iter_time
# 清空记录样本的LOSS列表
self.last_src_samples_loss = []
self.last_dst_samples_loss = []
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
这里的gan和真脸,我后面还要再测试一下gan和真脸开启后是每个循环执行一次好还是最后一次迭代执行好
|
|