def __getstate__(self): state = self.__dict__.copy() if hasattr(self, "model") and self.model is not None: buf = io.BytesIO() with h5py.File(buf, compression="lzf", mode="w") as h5: save_model(self.model, h5, overwrite=True, save_format="h5") buf.seek(0) state["model"] = buf if hasattr(self, "history"): from tensorflow.python.keras.callbacks import History history = History() history.history = self.history.history history.params = self.history.params history.epoch = self.history.epoch state["history"] = history return state
def target_to_value(self, target, **kwargs): h = History() with target.open("rb") as dumped: h.history = cloudpickle.load(dumped) return h