首页 > 解决方案 > tensorflow 急切执行在运行时发生变化

问题描述

我正在使用 tensor2tensor (1.9.0) 和 tensorflow 1.9。当我尝试tf.enable_eager_execution()在 t2t-decoder 中启用急切执行时,它工作得很好。但是,当程序在 tensor2tensor 的 python 代码中中断时,我发现急切执行已被禁用。试图在 t2t 框架内寻找任何可能禁用它的东西,但我找不到任何可能做到这一点的东西。

版本:t2t 1.9.0 tensorflow (cpu) 1.9.0 python 3.6 ubuntu 18.04

标签: tensorflowtensor2tensor

解决方案


我正在使用 python 3。我必须将 tensorflow 和 tf.enable_eager_execution 放在脚本的顶部

 import tensorflow as tf
 tf.enable_eager_execution()

 you may have to shutdown the kernal and jupyter notes than reopen them.

 a=tf.Variable([1,2])
 a.assign([5, 6])

 print(a.numpy())   

输出:

 [5,6]

推荐阅读