【发布时间】:2019-11-02 06:06:28
【问题描述】:
阅读 this 和 this answer 我了解到,对于 TensorFlow-2.0 上的非动态模型,Keras 将使用 AutoGraph。但是现在写一个回调来获取训练过程中变量的历史,
class TrainHistory(tf.keras.callbacks.Callback):
def on_train_begin(self, logs={}):
self.vars = []
def on_batch_end(self, batch, logs={}):
self.vars.append([v.numpy() for v in self.model.variables])
我看到可以使用热切张量的.numpy()方法。我期待像numpy() is only available when eager execution is enabled 这样的错误。将 Keras 与 TensorFlow-2.0 结合使用时是否会执行急切代码?
Here 有人提到,对于像卷积这样的计算密集型函数,tf.function-decorated 函数与 Eager 代码相比并没有太大的加速,但从示例中显示的数字来看,我猜这种差异可能对长时间的训练。在使用 tf.function 装饰的自定义训练函数上使用 GradientTape 而不是 Keras 的 fit() 方法在性能方面会更好吗?
【问题讨论】:
标签: python tensorflow keras tensorflow2.0