<bdo id='XsQ5n'></bdo><ul id='XsQ5n'></ul>

      <i id='XsQ5n'><tr id='XsQ5n'><dt id='XsQ5n'><q id='XsQ5n'><span id='XsQ5n'><b id='XsQ5n'><form id='XsQ5n'><ins id='XsQ5n'></ins><ul id='XsQ5n'></ul><sub id='XsQ5n'></sub></form><legend id='XsQ5n'></legend><bdo id='XsQ5n'><pre id='XsQ5n'><center id='XsQ5n'></center></pre></bdo></b><th id='XsQ5n'></th></span></q></dt></tr></i><div id='XsQ5n'><tfoot id='XsQ5n'></tfoot><dl id='XsQ5n'><fieldset id='XsQ5n'></fieldset></dl></div>
      <tfoot id='XsQ5n'></tfoot>
    1. <small id='XsQ5n'></small><noframes id='XsQ5n'>

        <legend id='XsQ5n'><style id='XsQ5n'><dir id='XsQ5n'><q id='XsQ5n'></q></dir></style></legend>
      1. 使用 Tensorflow 检查点在 C++ 中恢复模型

        Using Tensorflow checkpoint to restore model in C++(使用 Tensorflow 检查点在 C++ 中恢复模型)

        <small id='vND21'></small><noframes id='vND21'>

        <tfoot id='vND21'></tfoot>
          <bdo id='vND21'></bdo><ul id='vND21'></ul>
            <tbody id='vND21'></tbody>
            • <legend id='vND21'><style id='vND21'><dir id='vND21'><q id='vND21'></q></dir></style></legend>
              <i id='vND21'><tr id='vND21'><dt id='vND21'><q id='vND21'><span id='vND21'><b id='vND21'><form id='vND21'><ins id='vND21'></ins><ul id='vND21'></ul><sub id='vND21'></sub></form><legend id='vND21'></legend><bdo id='vND21'><pre id='vND21'><center id='vND21'></center></pre></bdo></b><th id='vND21'></th></span></q></dt></tr></i><div id='vND21'><tfoot id='vND21'></tfoot><dl id='vND21'><fieldset id='vND21'></fieldset></dl></div>

                  本文介绍了使用 Tensorflow 检查点在 C++ 中恢复模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我已经训练了一个我使用 Python 用 Tensorflow 实现的网络.最后,我用 tf.train.Saver() 保存了模型.现在我想使用 C++ 来使用这个预先训练好的网络进行预测.

                  I've trained a network that I implemented with Tensorflow using Python. In the end, I saved the model with tf.train.Saver(). And now I would like to use C++ to make predictions using this pre trained network.

                  我该怎么做?有没有办法转换检查点,以便我可以将它与 tiny-dnn 或 Tensorflow C++ 一起使用?

                  How can I do that ? Is there a way to convert checkpoint so I can use it with tiny-dnn or Tensorflow C++ ?

                  欢迎提出任何想法:) 谢谢!

                  Any idea is welcome :) thank you !

                  推荐答案

                  您可能应该在 SavedModel 格式,封装了计算图和保存的变量(tf.train.Saver只保存变量,所以你无论如何都必须保存图表).

                  You probably should export the model in the SavedModel format, which encapsulates the computational graph and the saved variables (tf.train.Saver only saves the variables, so you'd have to save the graph anyway).

                  然后您可以使用 LoadSavedModel.

                  You can then load the saved model in C++ using LoadSavedModel.

                  确切的调用取决于模型的输入和输出是什么.但是 Python 代码看起来像这样:

                  The exact invocation would depend on what the inputs and outputs of your model are. But the Python code would look something like so:

                  # You'd adjust the arguments here according to your model
                  signature = tf.saved_model.signature_def_utils.predict_signature_def(                                                                        
                    inputs={'image': input_tensor}, outputs={'scores': output_tensor})                                                                         
                  
                  
                  builder = tf.saved_model.builder.SavedModelBuilder('/tmp/my_saved_model')                                                                    
                  
                  builder.add_meta_graph_and_variables(                                                                                                        
                     sess=sess,                                                                                                                    
                     tags=[tf.saved_model.tag_constants.SERVING],                                                                                             
                     signature_def_map={                                                                                                       
                   tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY:                                                                
                          signature                                                                                                                        
                  })                                                                                                                                       
                  
                  builder.save()
                  

                  然后在 C++ 中你会做这样的事情:

                  And then in C++ you'd do something like this:

                  tensorflow::SavedModelBundle model;
                  auto status = tensorflow::LoadSavedModel(session_options, run_options, "/tmp/my_saved_model", {tensorflow::kSavedModelTagServe}, &model);
                  if (!status.ok()) {
                     std::cerr << "Failed: " << status;
                     return;
                  }
                  // At this point you can use model.session
                  

                  (请注意,使用 SavedModel 格式还允许您使用 TensorFlow Serving 提供模型,如果这对您的应用程序有意义)

                  (Note that using the SavedModel format will also allow you to serve models using TensorFlow Serving, if that makes sense for your application)

                  希望有所帮助.

                  这篇关于使用 Tensorflow 检查点在 C++ 中恢复模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?(静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么?)
                  How do I load a C DLL from the SXS in Python?(如何从 Python 中的 SXS 加载 C DLL?)
                  Can Cython code be compiled to a dll so C++ application can call it?(Cython 代码可以编译成 dll 以便 C++ 应用程序可以调用它吗?)
                  Delay Loading DLLs(延迟加载 DLL)
                  Throwing C++ exceptions across DLL boundaries(跨 DLL 边界抛出 C++ 异常)
                  Loading a dll from a dll?(从 dll 加载 dll?)
                    <tbody id='MtPvO'></tbody>

                  <small id='MtPvO'></small><noframes id='MtPvO'>

                  <tfoot id='MtPvO'></tfoot>

                      1. <i id='MtPvO'><tr id='MtPvO'><dt id='MtPvO'><q id='MtPvO'><span id='MtPvO'><b id='MtPvO'><form id='MtPvO'><ins id='MtPvO'></ins><ul id='MtPvO'></ul><sub id='MtPvO'></sub></form><legend id='MtPvO'></legend><bdo id='MtPvO'><pre id='MtPvO'><center id='MtPvO'></center></pre></bdo></b><th id='MtPvO'></th></span></q></dt></tr></i><div id='MtPvO'><tfoot id='MtPvO'></tfoot><dl id='MtPvO'><fieldset id='MtPvO'></fieldset></dl></div>
                          <legend id='MtPvO'><style id='MtPvO'><dir id='MtPvO'><q id='MtPvO'></q></dir></style></legend>
                            <bdo id='MtPvO'></bdo><ul id='MtPvO'></ul>