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

Refactor reset_state() in metrics.py to replace deprecated batch_set_value method. #27

Open
JacobJ17 opened this issue Nov 11, 2024 · 0 comments

Comments

@JacobJ17
Copy link

The reset_state function in coral_ordinal/metrics.py currently uses the tf.keras.backend.batch_set_value method, which has been deprecated in recent versions of TensorFlow/Keras.

File and Line Reference: reset_state function

def reset_state(self):
    """Resets all of the metric state variables at the start of each epoch."""
    K.batch_set_value([(v, 0) for v in self.variables])

I use coral-ordinal with Keras tuner, so the issue was caused after I started training by calling tuner.search. Training stopped after only 1 trial, and the only error message was AttributeError: 'str' object has no attribute 'name', however the program did not crash immediately. Instead, the program crashed a few lines later when calling tuner.get_best_models.

Proposed Solution: To avoid using the deprecated batch_set_value, I was able to use the .assign() method on each variable individually, as shown below:

def reset_state(self):
    for v in self.variables:
        v.assign(0)

This has worked for me with Tensorflow version 2.18.0 and Python 3.12.7

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

1 participant