Kevin Nathaniel
Kevin Nathaniel

Reputation: 49

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

Upvotes: 2

Views: 2080

Answers (2)

Srihari Humbarwadi
Srihari Humbarwadi

Reputation: 2642

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.

Upvotes: 3

Vishnuvardhan Janapati
Vishnuvardhan Janapati

Reputation: 3288

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!

Upvotes: 0

Related Questions