問題描述
我正在使用 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++的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!