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.
@Arnold2381,
Could you please provide the complete code to reproduce the issue, which helps us to analyse the issue in an effective way. Also could you please try to load your model inside the graph and take a look at this [comment](https://github.com/tensorflow/tensorflow/issues/47959#issuecomment-805986358) from the developer for the similar error. Thank you!
```

with graph.as_default():
        #load weights into the model
        loaded_model.load_weights("model.h5")
        #compile and evaluate loaded model
        loaded_model.compile(loss='sparse_categorical_crossentropy',optimizer='adam',metrics=['accuracy'])
        # perform the prediction
        out = loaded_model.predict(img)
        print(out)
        print(class_names[np.argmax(out)])
        # convert the response to a string
        response = class_names[np.argmax(out)]
        return str(response)
``` ```
em = tf.keras.models.load_model(model_path)
model = {
    'key': em,
}    
em = model['key']
dta = input_data['data']
df = np.array(dta).reshape(1, -1)

ed = em.predict(df).tolist()

``` @Arnold2381,
I was facing a different error while executing the mentioned code on tensorflow v2.12. Kindly find the gist of it [here](https://colab.research.google.com/gist/tilakrayal/b3994a91362a35237ef9289d7c17115b/untitled1176.ipynb) and provide complete dependencies.
Also there is a mix of graph mode and eager mode (and by default TF2.x is eager). Error is mainly due to mix of both modes.  Thank you! This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. Closing this as stale. Please reopen if this is still a valid request. Thank you! Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/60606">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/60606">No</a>

<details><summary>Click to expand!</summary> 
 
 ### Issue Type

Bug

### Have you reproduced the bug with TF nightly?

Yes

### Source

source

### Tensorflow Version

2.6.0

### Custom Code

Yes

### OS Platform and Distribution

_No response_

### Mobile device

_No response_

### Python version

_No response_

### Bazel version

_No response_

### GCC/Compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current Behaviour?

We are using tensorflow version 2 where eager model is enabled by default. 

while predicting from trained model we are getting this error. 
```
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.
```

As a workaround, for time being we resolved this issue, by disabling eager mode, and load the model inside graph mode.

We would like to know, how can we resolve this issue without disabling the eager mode. 

### Standalone code to reproduce the issue

```shell
This is not an issue, which can be reproduced as its happening only for few requests.
```


### Relevant log output

_No response_</details>