rn_rnn_model.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:rngru 作者: rneilson 项目源码 文件源码
def savetofile(self, outfile):
        """Save model parameters to file."""

        # Pickle non-matrix params into bytestring, then convert to numpy byte array
        pklbytes = pickle.dumps({'hyper': self.hyper, 'epoch': self.epoch, 'pos': self.pos}, 
            protocol=pickle.HIGHEST_PROTOCOL)
        p = np.fromstring(pklbytes, dtype=np.uint8)

        # Gather parameter matrices and names
        pvalues = { n:m.get_value() for n, m in self.params.items() }

        # Now save params and matrices to file
        try:
            np.savez_compressed(outfile, p=p, **pvalues)
        except OSError as e:
            raise e
        else:
            if isinstance(outfile, str):
                stdout.write("Saved model parameters to {0}\n".format(outfile))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号