作家
登录

面向机器智能的TensorFlow实践:产品环境中模型的部署

作者: 来源: 2017-04-26 16:02:39 阅读 我要评论

float score() const; 
  •  
  • void set_score(float value); 
  •  
  • ... 
  •  
  •  
  • 可以看到,proto定义如今变成了每种类型的C++类接口。它们的实现也是主动生成的,如许便可直接应用它们。

    实现揣摸办事器

    为实现ClassificationService::Service,须要加载导出模型并对其调用揣摸办法。这可经由过程一个SessionBundle对象来实现,该对象是大年夜导出的模型创建的,它包含了一个带有完全加载的数据流图的TF会话对象,以及带有定义在导出对象上的分类签名的元数据。

    为了大年夜导出的文件路径创建SessionBundle对象,可定义一个便捷函数,以处理这个样板文件:

    1. #include <iostream> 
    2.  
    3. #include <memory> 
    4.  
    5. #include <string> 
    6.  
    7.  
    8. #include <grpc++/grpc++.h> 
    9.  
    10. #include "classification_service.grpc.pb.h" 
    11.  
    12.  
    13. #include "tensorflow_serving/servables/tensorflow/ 
    14.  
    15. session_bundle_factory.h" 
    16.  
    17.  
    18. using namespace std; 
    19.  
    20. using namespace tensorflow::serving; 
    21.  
    22. using namespace grpc; 
    23.  
    24.  
    25. unique_ptr<SessionBundle> createSessionBundle(const string& 
    26.  
    27. pathToExportFiles) { 
    28.  
    29. SessionBundleConfig session_bundle_config = 
    30.  
    31. SessionBundleConfig(); 
    32.  
    33. unique_ptr<SessionBundleFactory> bundle_factory; 
    34.  
    35. SessionBundleFactory::Create(session_bundle_config, 
    36.  
    37. &bundle_factory); 
    38.  
    39.  
    40.         unique_ptr<SessionBundle> sessionBundle; 
    41.  
    42. bundle_factory- 
    43.  
    44. >CreateSessionBundle(pathToExportFiles, &sessionBundle); 
    45.  
    46.  
    47.        return sessionBundle; 
    48.  
    49.  

    在这段代铝闼楝我们应用了一个SessionBundleFactory类创建了SessionBundle对象,并将其设备为大年夜pathToExportFiles指定的路径中加载导出的模型。最后返回一个指向所创建的SessionBundle实例的unique指针。

    1. class ClassificationServiceImpl final : public 
    2.  
    3. ClassificationService::Service { 
    4.  
    5. private: 
    6.  
    7. unique_ptr<SessionBundle> sessionBundle; 
    8.  
    9. public
    10.  
    11. ClassificationServiceImpl(unique_ptr<SessionBundle> 
    12.  
    13. sessionBundle) : 
    14.  
    15. sificationServiceImpl(unique_ptr<Sessi 
    16.  
    17. Status classify(ServerContext* context, const 

        推荐阅读

        传统存储市场正遭遇来自横向扩展SDS 的威胁

      传统的存储厂商正面对着前所未竽暌剐的压力。软件定义存储与公有云存储(也是基于横向扩大的SDS技巧)相浇忧⒛解决筹划正在蚕食传统的存储市场,如Dell EMC的VNX、HPE的Smart Array、NetApp的E系列和FAS。我同样认为>>>详细阅读


      本文标题:面向机器智能的TensorFlow实践:产品环境中模型的部署

      地址:http://www.17bianji.com/lsqh/34985.html

    关键词: 探索发现

    乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

    网友点评
    自媒体专栏

    评论

    热度

    精彩导读
    栏目ID=71的表不存在(操作类型=0)