python - 如何将亲笔签名的好处与训练循环结合起来?
问题描述
如何使用autograph
“魔术”提高以下代码的执行速度?
从这里给定代码:https ://www.tensorflow.org/alpha/tutorials/generation/dcgan
特别是这部分https://www.tensorflow.org/alpha/tutorials/generation/dcgan#train_the_model:
def train(dataset, epochs):
for epoch in range(epochs):
start = time.time()
for image_batch in dataset:
train_step(image_batch)
# Produce images for the GIF as we go
display.clear_output(wait=True)
generate_and_save_images(generator,
epoch + 1,
seed)
# Save the model every 15 epochs
if (epoch + 1) % 15 == 0:
checkpoint.save(file_prefix = checkpoint_prefix)
print ('Time for epoch {} is {} sec'.format(epoch + 1, time.time()-start))
# Generate after the final epoch
display.clear_output(wait=True)
generate_and_save_images(generator,
epochs,
seed)
tf.data.Dataset
并考虑将 a 包装到@tf.function
通话中的好处。如此处所示:将 tf.data.Dataset 包装到 tf.function 中会提高性能吗?.
我试过的:
由于. train()
_ @tf.function
_ train
但是:此代码通常需要用于日志记录、检查点等。
问题:
- 这段代码如何利用两全其美?
- 或者甚至有可能吗?
解决方案
推荐阅读
- php - 如何在 Laravel 中验证电子邮件地址是否是有效的 PayPal 电子邮件地址
- emacs - 组织模式工厂 UML 问题
- powerbi - PowerBI - 如何查看链接到的所有页面
- dataframe - 将带有熊猫的数据框插入 SAP HANA 报价错误
- c++ - 如何使用模板化方法将函数作为输入,该函数可用于每个签名
- java - 如何获取单选按钮中分配的值?
- angular - Angular 反应式表单自定义验证:更新第一次无法正常工作的更改
- selenium - 将 Chromedriver 用于无头浏览器时出现“Permissions-Policy 标头错误”
- sqlite - 将两个表中的计数合并到一个表中
- macos - 如何获取 DriverKit 系统扩展日志输出