Unknown metric error when loading a model trained with stateful metrics
See original GitHub issueHi everyone,
I’m trying to load a saved model which has been trained with a custom stateful metric (object of the class ValidAccuracy
using the code
dependencies = {
'ValidAccuracy': ValidAccuracy
}
model = keras.models.load_model(model_file, custom_objects=dependencies)
and I get the error
ValueError: Unknown metric function: {'config': {'batch_size': 32, 'name': 'valid_accuracy', 'trainable': False}, 'class_name': <class 'spearec.run.metrics.ValidAccuracy'>}
.
Is there any solution or workaround?
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Unknown metric error when loading keras model
I have trained my regression model with no issues. Trains and tests perfectly. I used the model.save(model_filename) to save it.
Read more >Metrics - Keras
Metric functions are similar to loss functions, except that the results from evaluating a metric are not used when training the model. Note...
Read more >Keras Metrics: Everything You Need to Know - neptune.ai
Keras metrics are functions that are used to evaluate the performance of your deep learning model. Choosing a good metric for your problem...
Read more >tensorflow could not interpret metric function identifier - You.com
train model with keras.metrics.Precision and save as a hdf5 file load model from the hdf5 file, got the ValueError. ValueError: Unknown metric function: ......
Read more >Evaluate the Performance of Deep Learning Models in Keras
Use a manual verification dataset. Use an Automatic Verification Dataset. Keras can separate a portion of your training data into a validation ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Stateful Metrics are custom layers:
If you really want to load a custom model with custom layers: https://github.com/keras-team/keras/issues/4871.
Or you can just do
load_weights
.I’m of the opinion that
load_model
shouldn’t even exist. Have a function that defines your network, train your model, save the weights, create the network, load your weights, predict.You shouldn’t need the training metrics, or the optimizer to do predictions.
should solve the issue.
Stateful metric inherits from layer and forces it to
lower_case_underscore
. As per the error message, it is looking forvalid_accuracy
and notValidAccuracy
.