ppl*_*ski 43 c++ theano conv-neural-network keras tensorflow
我正在使用Keras(与Theano)来训练我的CNN模型.有谁知道如何在我的C++应用程序中使用它?有没有人尝试类似的东西?我有想法写一些python代码,它将生成一个带有网络功能的c ++代码 - 有什么建议吗?
Tob*_*ann 14
我发现自己处于类似的情况,但不仅需要支持C++中顺序Keras模型的前向传递,还需要使用功能API构建更复杂的模型.
所以我写了一个名为frugally-deep的新库.你可以在GitHub上找到它并在MIT许可证下发布:https://github.com/Dobiasd/frugally-deep
除了支持许多常见的图层类型之外,它还可以在单个CPU上跟上(有时甚至击败)TensorFlow的性能.您可以在回购中找到一些常见模型的最新基准测试结果.
通过自动测试节俭深度保证C++中使用它的模型的输出与在Python中使用Keras运行时完全相同.
如果您的keras模型是使用tensorflow后端训练的,则可以按照以下代码将keras模型另存为tensorflow模型:https : //github.com/amir-abdi/keras_to_tensorflow
这是代码的简短版本:
from keras import backend as K
from tensorflow.python.framework import graph_util
from tensorflow.python.framework import graph_io
weight_file_path = 'path to your keras model'
net_model = load_model(weight_file_path)
sess = K.get_session()
constant_graph = graph_util.convert_variables_to_constants(sess, sess.graph.as_graph_def(), 'name of the output tensor')
graph_io.write_graph(constant_graph, 'output_folder_path', 'output.pb', as_text=False)
print('saved the constant graph (ready for inference) at: ', osp.join('output_folder_path', 'output.pb'))
Run Code Online (Sandbox Code Playgroud)
小智 5
你可以试试这个 https://github.com/gosha20777/keras2cpp
Keras2cpp 是一个小型库,用于从 C++ 应用程序运行经过训练的 Keras 模型,无需任何依赖。
支持的 Keras 层: - Dense - Convolution1D - Convolution2D - Convolution3D - Flatten - ELU - Activation - MaxPooling2D - Embedding - LocallyConnected1D - LocallyConnected2D - LSTM - GRU - CNN - BatchNormalization
支持的激活:-线性-relu-softplus-tanh-sigmoid-hard_sigmoid-elu-softsign-softmax
设计目标: