可以看到,proto定义如今变成了每种类型的C++类接口。它们的实现也是主动生成的,如许便可直接应用它们。
实现揣摸办事器
为实现ClassificationService::Service,须要加载导出模型并对其调用揣摸办法。这可经由过程一个SessionBundle对象来实现,该对象是大年夜导出的模型创建的,它包含了一个带有完全加载的数据流图的TF会话对象,以及带有定义在导出对象上的分类签名的元数据。
为了大年夜导出的文件路径创建SessionBundle对象,可定义一个便捷函数,以处理这个样板文件:
- #include <iostream>
- #include <memory>
- #include <string>
- #include <grpc++/grpc++.h>
- #include "classification_service.grpc.pb.h"
- #include "tensorflow_serving/servables/tensorflow/
- session_bundle_factory.h"
- using namespace std;
- using namespace tensorflow::serving;
- using namespace grpc;
- unique_ptr<SessionBundle> createSessionBundle(const string&
- pathToExportFiles) {
- SessionBundleConfig session_bundle_config =
- SessionBundleConfig();
- unique_ptr<SessionBundleFactory> bundle_factory;
- SessionBundleFactory::Create(session_bundle_config,
- &bundle_factory);
- unique_ptr<SessionBundle> sessionBundle;
- bundle_factory-
- >CreateSessionBundle(pathToExportFiles, &sessionBundle);
- return sessionBundle;
- }
在这段代铝闼楝我们应用了一个SessionBundleFactory类创建了SessionBundle对象,并将其设备为大年夜pathToExportFiles指定的路径中加载导出的模型。最后返回一个指向所创建的SessionBundle实例的unique指针。
- class ClassificationServiceImpl final : public
- ClassificationService::Service {
- private:
- unique_ptr<SessionBundle> sessionBundle;
- public:
- ClassificationServiceImpl(unique_ptr<SessionBundle>
- sessionBundle) :
- sificationServiceImpl(unique_ptr<Sessi
- Status classify(ServerContext* context, const
推荐阅读
传统的存储厂商正面对着前所未竽暌剐的压力。软件定义存储与公有云存储(也是基于横向扩大的SDS技巧)相浇忧⒛解决筹划正在蚕食传统的存储市场,如Dell EMC的VNX、HPE的Smart Array、NetApp的E系列和FAS。我同样认为>>>详细阅读
本文标题:面向机器智能的TensorFlow实践:产品环境中模型的部署
地址:http://www.17bianji.com/lsqh/34985.html
1/2 1