def loadfromfile(cls, infile):
"""Load model parameters from file and rebuild model."""
with np.load(infile) as f:
# Extract hyperparams and position
p = f['p']
hparams = pickle.loads(p.tobytes())
hyper, epoch, pos = hparams['hyper'], hparams['epoch'], hparams['pos']
# Load matrices
pvalues = { n:f[n] for n in cls.pnames }
# Create instance
if isinstance(infile, str):
stdout.write("Loaded model parameters from {0}\n".format(infile))
stdout.write("Rebuilding model...\n")
model = cls(hyper, epoch, pos, pvalues)
return model
评论列表
文章目录