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

Metrics are not pickleable #47

Open
chrissype opened this issue Sep 30, 2019 · 4 comments
Open

Metrics are not pickleable #47

chrissype opened this issue Sep 30, 2019 · 4 comments

Comments

@chrissype
Copy link
Contributor

chrissype commented Sep 30, 2019

Instantiated metrics are not pickleable, as __init__ instantiates tf variables, which cannot be pickled.

This means that keras models trained with one of the metrics, and then saved, cannot be opened without knowing the dict structure for the 'custom_objects' argument when loading the model. Without using dill, one cannot pickle said dict, which would make delivering a complete model possible. Tools like mlflow are able to track and return complete keras models, however only if the model and custom_objects are both pickleable.

I've come up with a moderately ugly solution that waits until a metric is called to instantiate any tf variables, let me know if you want to see it.

@ybubnov
Copy link
Member

ybubnov commented Oct 1, 2019

Hi @chrissype, thank you for revealing the problem. Yes, definitely would be great to see to what you've came up, probably we could work on a better solution eventually.

@chrissype
Copy link
Contributor Author

Sure thing, I have opened a pull request so you can see what I did. The tests all pass on my machine.

The alternative I could think of was to store the running total not as a tensorflow tensor, but it looks like you'd have to .eval() the results of the metric calculation and I don't know how expensive that would be.

@ybubnov
Copy link
Member

ybubnov commented Oct 3, 2019

@chrissype, eventually, it looks like this effort of fixing this issue is useless, since keras already provides stateful metrics in it's API: https://github.com/keras-team/keras/blob/master/keras/metrics.py

Probably, it would be better to deprecate this repository, since it's completely integrated into the keras.

@chrissype
Copy link
Contributor Author

Well spotted, can't believe I'd missed that. I did always find it very weird that they took them out.

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

2 participants