Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: ValueError: Cannot get result() since the metric has not yet been built during model.fit() #20273

Closed
rohitcodism opened this issue Sep 20, 2024 · 6 comments

Comments

@rohitcodism
Copy link

rohitcodism commented Sep 20, 2024

1. Title:

Error: ValueError: Cannot get result() since the metric has not yet been built during model.fit()

2. Description:

Summary

I encountered a ValueError: Cannot get result() since the metric has not yet been built when trying to train my model using model.fit(). This happens in the first epoch, and the error is thrown from compile_utils.py.

## Error Traceback
```plaintext
Epoch 1/10
Traceback (most recent call last):
  File "path/to/train.py", line 85, in <module>
    model_test_1.fit(
  File "C:\Path\to\Python312\Lib\site-packages\keras\src\utils\traceback_utils.py", line 122, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "C:\Path\to\Python312\Lib\site-packages\keras\src\trainers\compile_utils.py", line 356, in result
    raise ValueError(
ValueError: Cannot get result() since the metric has not yet been built.

Environment Details

  • TensorFlow Version: 2.17.0
  • Keras Version: 3.5.0
  • Python Version: 3.12.4

Additional Information

I am using a model with two inputs, and I have defined the metrics as part of model.compile(). However, I am still encountering the above error.

Any guidance on what could be causing this issue would be appreciated. Thank you!

@sachinprasadhs
Copy link
Collaborator

Could you please provide some sample reproducible code to debug. Thanks!

@james77777778
Copy link
Contributor

@rohitcodism
This should be fixed in the master branch. If you encounter the same issue: #20188

You can test it by installing the latest version of keras:

pip3 install keras-nightly

@rohitcodism
Copy link
Author

The issue is resolved when using
Tensorflow 2.15.0

but
Tensorflow 2.17.0 still has the issue.

@sachinprasadhs
Copy link
Collaborator

@rohitcodism , Use keras directly for your model, since the above linked fix will be available in Keras-nightly version, where Tensorflow 2.17.0 uses Keras >=3.2
Example:

!pip install keras-nightly
import keras
from keras.layers import Dense

@rohitcodism
Copy link
Author

Okay, I have resolved the issue, Thank You !!

Copy link

Are you satisfied with the resolution of your issue?
Yes
No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants