首页 > 解决方案 > Under what condition can we use @tf.function?

问题描述

I have heard that tf.function can build graph and accelerate computation. But when can we use it?

From another answer, seems like:

when we are not using built-in functions

Any more specific answer?

标签: functiontensorflow

解决方案


这是一个计算 tf.function 优点的链接想象一下你有一个损失函数,在你的函数顶部添加这个关键字可以帮助 Tensorflow 更快地运行它,但是你可能会遇到类似的错误

ValueError: tf.function-decorated function tried to create variables on non-first call.

如果您没有在第一次运行时初始化所有变量。


推荐阅读