简体   繁体   English

将 keras 模型保存到数据库

[英]Save keras model to database

I created a keras model (tensorflow) and want to store it in my MS SQL Server database.我创建了一个 keras 模型(tensorflow)并想将它存储在我的 MS SQL Server 数据库中。 What is the best way to do that?最好的方法是什么? pyodbc.Binary(model) throws an error. pyodbc.Binary(model) 抛出错误。 I would prefer a way without storing the model in the file system first.我更喜欢一种不先将模型存储在文件系统中的方法。

Thanks for any help谢谢你的帮助

It seems that there is no clean solution to directly store a model incl.似乎没有干净的解决方案来直接存储模型,包括。 weights into the database.权重存入数据库。 I decided to store the model as h5 file in the filesystem and upload it from there into the database as a backup.我决定将模型作为 h5 文件存储在文件系统中,并将其从那里上传到数据库中作为备份。 For predictions I load anyway the model from the filesystem as it is much faster than getting it from the database for each prediction.对于预测,我无论如何都从文件系统加载模型,因为它比每次预测都从数据库中获取模型要快得多。

The best approach would be to save it as a file in the system and just save the path in the database.最好的方法是将其保存为系统中的文件,并将路径保存在数据库中。 This technique is usually used to store large files like images since databases usually struggle with them.这种技术通常用于存储像图像这样的大文件,因为数据库通常很难处理它们。

Well, you can save a model as a JSON like:好吧,您可以将模型另存为 JSON,例如:

json_string = model.to_json()

And then cast it to string and save normally to the BD.然后将其转换为字符串并正常保存到BD。

Or use native MS SQL solution for JSON fields explained here .或者对此处解释的 JSON 字段使用本机 MS SQL 解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM