forked from glennhickey/teHmm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
modelIO.py
33 lines (27 loc) · 820 Bytes
/
modelIO.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python
#Copyright (C) 2013 by Glenn Hickey
#
#Released under the MIT license, see LICENSE.txt
import os
import sys
import numpy as np
import pickle
import logging
from numpy.testing import assert_array_equal, assert_array_almost_equal
from .hmm import MultitrackHmm
from .cfg import MultitrackCfg
def loadModel(path):
""" load an hmm or cfg from a pickle file """
f = open(path, "rb")
model = pickle.load(f)
f.close()
assert isinstance(model, MultitrackCfg) or isinstance(model, MultitrackHmm)
model.validate()
return model
def saveModel(path, model):
""" save an hmm or cfg to a pickle file """
assert isinstance(model, MultitrackCfg) or isinstance(model, MultitrackHmm)
model.validate()
f = open(path, "wb")
pickle.dump(model, f, 2)
f.close()