diff --git a/gordo/machine/model/models.py b/gordo/machine/model/models.py index c230b75b6..23647325e 100644 --- a/gordo/machine/model/models.py +++ b/gordo/machine/model/models.py @@ -4,6 +4,7 @@ import logging import io import importlib +import tempfile from pprint import pformat from typing import Union, Callable, Dict, Any, Optional, Tuple from abc import ABCMeta @@ -177,11 +178,11 @@ 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: - self.model.save(h5, overwrite=True, save_format="h5") - buf.seek(0) - state["model"] = buf + with tempfile.NamedTemporaryFile(suffix='.h5') as tf: + with h5py.File(tf.name, compression="lzf", mode="w") as h5: + save_model(self.model, h5, overwrite=True) + tf.seek(0) + state["model"] = tf if hasattr(self, "history"): from tensorflow.python.keras.callbacks import History