Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
890 views
in Technique[技术] by (71.8m points)

python - tensorflow eager execution issue

I am having issues with tensorflow, keras, building models and then calling predict.

My neural network is quite simple and is built as follows:

 def create_model():
        
        model = Sequential()
        model.add(Dense(24, input_shape=(17, 5), activation = 'relu'))
        model.add(Dense(12, activation = "relu"))

        model.add(Dense(3, activation="linear"))
        model.compile(loss="mse", optimizer=Adam(lr=0.001), metrics=['accuracy'])
        return model

However, after compiling, I got:

ValueError: Calling `Model.predict` in graph mode is not supported when the `Model` instance was constructed with eager mode enabled. Please construct your `Model` instance in graph mode or call `Model.predict` with eager mode enabled.

So on advice of another post I added the following to compile()

run_eagerly = True

Even after I add this I still get the same error. When investigating I found that when I imported tensorflow:

import tensorflow as tf
print(tf.__version__)
print(tf.executing_eagerly())

2.4.0
True

But if I run the same code after compiling:

2.4.0
False

So at some point eager execution is being switched off automatically, and then I am unable to call predict.

Can somebody help me with understanding why this is happening and the solution?

question from:https://stackoverflow.com/questions/65939148/tensorflow-eager-execution-issue

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...