Python 代码解析:生成模型的采样评估和保存
这段代码的主要功能是评估生成模型的采样性能,并保存模型和参数。
- 首先,使用
evaluate_samples函数计算生成模型g_model和辅助模型aux_model在最大序列长度为metadata.max_len的条件下的采样准确率,将结果存储在变量sampling_acc中。 - 接着,将采样准确率打印出来。
- 然后,使用生成模型
g_model对固定的采样标签fixed_sampling_labels和固定的噪声向量fixed_sampling_z进行采样,得到最大序列长度为metadata.max_len的生成样本,将结果存储在变量test_samples中。 - 最后,将训练过程中的各种参数和模型保存到文件中,以备后续使用。其中,
checkpoint和disc_checkpoint分别是生成模型和判别模型的 TensorFlow Checkpoint 对象,save_prefix和d_save_prefix分别是生成模型和判别模型的保存前缀。
代码示例:
sampling_acc = evaluate_samples(
g_model, aux_model, metadata.max_len)
print('sampling_acc:')
print('** {} ** '.format(sampling_acc))
test_samples = g_model.sample(
fixed_sampling_labels, fixed_sampling_z, max_len=metadata.max_len)
checkpoint.save(file_prefix=save_prefix)
disc_checkpoint.save(file_prefix=d_save_prefix)
原文地址: https://www.cveoy.top/t/topic/nnou 著作权归作者所有。请勿转载和采集!