I'm working with Keras, as bundled with Tensorflow 2.1. I am trying many different model architectures. I have learned that Keras Model
objects are difficult, if not impossible, to serialize using Python's pickle
. Using JSON
, of course, is out of the question.
Writing a Model
object to disk using pickle.dump()
does not fail. However, when you attempt to reload it, you've lost your model weights. I'm not sure why. To get around the problem, I've built a Python wrapper class for Keras Models which can reconstruct the model from data which can be serialized. I have to recompile the Model and set its weights once it has been reloaded from disk, but that's not a huge obstacle.
Now, I now want to do the same thing for an Optimizer
that I've done for my models. I've already determined that JSON rejects Optimizers, and pickle accepts them. But I also know from working with Model objects that unpickling may not work.
I have a possibly-related problem with Tensorflow Dataset
objects. I can create a subclass of Dataset
, but I can only add attributes and NEW methods. I was unable to override an existing Dataset method (I wanted to modify Dataset.padded_batch()
).
Before I waste time attempting to apply Pythonic approaches to Keras (Tensorflow) objects: does anyone know which of these objects can be serialized and/or subclassed? Is there a guide somewhere? For now, I only really need to know about Optimizers, but in the future I suppose I might try to save or subclass another object.
Thanks for your advice.