将 Keras 模型转换为 C++ [英] Convert Keras model to C++

查看:45
本文介绍了将 Keras 模型转换为 C++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Keras(和 Theano)来训练我的 CNN 模型.有谁知道如何在我的 C++ 应用程序中使用它?有没有人尝试过类似的东西?我想写一些 python 代码来生成一个带有网络函数的 C++ 代码 - 有什么建议吗?

I am using Keras (with Theano) to train my CNN model. Does anyone has idea how can I use it in my C++ application? Does anyone tried something similar? I have idea to write some python code that will generate a c++ code with network functions - any suggestion on it?

我在这里发现了一个类似的问题,如何在C++ 但没有答案.

I found a similar question here how to use Tensorflow Keras model in C++ but without answer.

推荐答案

为了回答我自己的问题并有一个解决方案 - 我写了一个简单的 C++ 解决方案,名为 keras2cpp(其代码可在 github 上找到).

To answer my own question and have a solution - I wrote a plain c++ solution called keras2cpp (its code available on github).

在此解决方案中,您存储网络架构(在 json 中)和权重(在 hdf5 中).然后,您可以使用提供的脚本将网络转储到纯文本文件中.您可以在纯 C++ 代码中使用获得的带有网络的文本文件.不依赖于 python 库或 hdf5.它应该适用于 theano 和 tensorflow 后端.

In this solution you store network architecture (in json) and weights (in hdf5). Then you can dump a network to a plain text file with provided script. You can use obtained text file with network in pure c++ code. There are no dependencies on python libraries or hdf5. It should work for theano and tensorflow backend.

这篇关于将 Keras 模型转换为 C++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆