eager模式造成的bug

在 tensorflow1.x 版本中,可以通过命令 tf.enable_eager_execution() 开启eager模式,但是在该模式下,使用 tf.keras.layers.Input 会遇到问题

import tensorflow as tf
tf.enable_eager_execution()

x = tf.keras.layers.Input(shape=[2,10])
x_cut = x[:,0,:]
print(x_cut.shape)

得到的结果是

<unknown> 

由于程序不知道 x_cut 的维度,因此在调用 x_cut 的时候会出现报错。

而在非eager模式下可以得到正确结果

(?,10)

所以说,在 tensorflow1.x 中不要随便开启 eager 模式

原文地址:https://www.cnblogs.com/bill-h/p/14134936.html