Skip to content

Commit

Permalink
Fix: change saving to tempfile
Browse files Browse the repository at this point in the history
  • Loading branch information
RollerKnobster committed Jun 24, 2024
1 parent 3696b11 commit 92a537f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions gordo/machine/model/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 92a537f

Please sign in to comment.