From 0b2ea43d5cfcd41b940358cd0500e43da7186041 Mon Sep 17 00:00:00 2001 From: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com> Date: Wed, 2 Sep 2020 18:00:07 -0500 Subject: [PATCH] fix example --- rfcs/20200902-pickle-for-keras/README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rfcs/20200902-pickle-for-keras/README.md b/rfcs/20200902-pickle-for-keras/README.md index 9e9d1c571..b25ef54ee 100644 --- a/rfcs/20200902-pickle-for-keras/README.md +++ b/rfcs/20200902-pickle-for-keras/README.md @@ -48,6 +48,8 @@ Examples that could be resolved using `Model.save` (but the user tried pickle fi * [SO #51878627](https://stackoverflow.com/questions/51878627/pickle-keras-ann) +Here is an post describing how PyTorch ran into similar issues and how they resolved them: [link](https://matthewrocklin.com/blog/work/2018/07/23/protocols-pickle) + ## User Benefit * Lessen the learning curve for new Keras/TF users since they will be able to @@ -98,7 +100,9 @@ Solution (2) would look something like this (assuming `Model.save` worked with ` class Model: def __reduce_ex__(self, protocol): - return tf.keras.models.load_model, (self.save(io.BytesIO()),) + b = io.BytesIO() + self.save(b) + return load_model, (b.get_value()),) # where load_model is tf.keras.models.load_model ``` By implementing this in all of Keras' base classes, things will automatically work