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

String "loss" being passed to metric_name() instead of loss func name #313

Open
Zanchet2020 opened this issue Feb 11, 2024 · 9 comments
Open

Comments

@Zanchet2020
Copy link

I'm new to ML and I'm just following a tutorial right now, but I'm getting the error:

ValueError: Could not interpret metric identifier: loss

at:
\keras\src\metrics\__init__.py:205, in get(identifier)

It seems like in the wrapper.py line 532 metric_name(key) should receive the name of a loss function, but it's actually receiving the string "loss"

If inside keras_metric_get I manually set identifier = "binary_crossentropy" it works fine

@Zanchet2020 Zanchet2020 changed the title String "loss" being passed to metric_name() instead of metric name String "loss" being passed to metric_name() instead of loss func name Feb 11, 2024
@adriangb
Copy link
Owner

Would you like to make a PR with a test and a fix since it sounds like you've already figured out where the problem is?

@Zanchet2020
Copy link
Author

I can try, though I'm not sure I'm capable of doing it lol

@adriangb
Copy link
Owner

Give it a shot! Feel free to ask questions.

@CasperKjaerhus
Copy link

I am facing this exact issue as well using keras 3.0.5/tensorflow 2.16.1

@johloe11
Copy link

Looks like the issue is with how the _fit_keras_model() method in the wrappers.py file tries to filter out Keras keys. The value error seems to have changed. if you change line 535 from if "Unknown metric function" not in str(e): to if "Unknown metric function" not in str(e) and "Could not interpret metric identifier" not in str(e): it works as expected.

@adriangb
Copy link
Owner

This is definitely a bug. I’ll try to fix it this week, but PRs are always welcome. I’d suggest a more robust pattern (if key == “loss” or key[:4] == “val_” or similar, suggest looking into keras docs).

@lazarust
Copy link

lazarust commented Apr 1, 2024

Is someone already working on fixing this? I'm now running into it too

@adriangb
Copy link
Owner

adriangb commented Apr 1, 2024

If you're running into this issue I'd guess you're using an unsupported version of Keras (e.g. Keras 3.0). We don't pin upper versions (which is considered best practice). It's an unfortunate tradeoff you need to make as a Python maintainer.

For now you'll either need use a supported version of Keras / Tensorflow (e.g. Tensorflow 2.12.X without the standalone Keras package) or wait for #317

@adriangb
Copy link
Owner

adriangb commented Apr 7, 2024

Could you please try #317 (pip install -U 'git+https://github.com/adriangb/scikeras.git@keras-3') and see if it fixes your problem? Thanks!

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

No branches or pull requests

5 participants