'Run keras.Models.fit() in graph
How to run keras.model.fit() in graph not with eager execution...??
I tried to run my model in graph by using tf.compat.v1.disable_eager_execution(), but the code return error: numpy must be run with eager execution
The error appear after checkpoint model
I’m using tensorflow GpU 2.1.0 and keras 2.3.1
Solution 1:[1]
In tensorflow2.x, model.fit()
runs in graph mode by default, you can control this behavior by using the run_eagerly
argument in the model.compile(...)
method, which defaults to False
.
Solution 2:[2]
Even though eager mode is by default in TF2.x
, under the hood keras.model.fit()
run in graph mode for faster computation. If you want to use some advanced functionality of TF2.x
and want to use graph mode as in TF1.x
, then import tensorflow as follows
import tensorflow.compat.v1 as tf
Mixing functionality of TF1.x
and TF2.x
by using tf.compat.v1.disable_eager_execution()
is not suggested. It could result in lot of issues down the line. Thanks!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Parham |
Solution 2 | Vishnuvardhan Janapati |