问题:
tf 1x 的代码迁移到 tf 2x时出现错误:
ValueError: tf.function-decorated function tried to create variables on non-first call
解决方案:
在model.compiler()之后添加
model.run_eagerly = True
但是对tf 1x 定义的一些函数提示
WARNING:tensorflow:AutoGraph could not transform <function drop_connect at 0x0000024E55A0DA60> and will run it as-is.
Please report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output.
Cause: module 'gast' has no attribute 'Index'
To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert
根据提示对函数,例如这里的drop_connect,前添加如下代码即可。
@tf.autograph.experimental.do_not_convert