小编a.e*_*ais的帖子

从Censorflow中的.meta文件中加载图形以进行推理

我使用tensorflow 1.5.1训练了一些模型,我有这些模型的检查点(包括.ckpt和.meta文件).现在我想使用这些文件在c ++中进行推理.

在python中,我将执行以下操作来保存和加载图形和检查点.保存:

    images = tf.placeholder(...) // the input layer
    //the graph def
    output = tf.nn.softmax(net) // the output layer
    tf.add_to_collection('images', images)
    tf.add_to_collection('output', output)
Run Code Online (Sandbox Code Playgroud)

推理我恢复图形和检查点,然后从集合中恢复输入和输出层,如下所示:

    meta_file = './models/last-100.meta'
    ckpt_file = './models/last-100'
    with tf.Session() as sess:
        saver = tf.train.import_meta_graph(meta_file)
        saver.restore(sess, ckpt_file)
        images = tf.get_collection('images')
        output = tf.get_collection('output')
        outputTensors = sess.run(output, feed_dict={images: np.array(an_image)})
Run Code Online (Sandbox Code Playgroud)

现在假设我像往常一样在python中进行保存,如何使用python中的简单代码在c ++中进行推理和恢复?

我找到了示例和教程,但对于tensorflow版本0.7 0.12,相同的代码不适用于1.5版本.我在tensorflow网站上找不到使用c ++ API恢复模型的教程.

c++ tensorflow

2
推荐指数
1
解决办法
3778
查看次数

标签 统计

c++ ×1

tensorflow ×1