借助这段代码,便可经由过程敕令bazel run :server 9999 /tmp/inception-v3/export/{timestamp}安闲器中运行揣摸办事器。
客户端应用
因为gRPC是基于HTTP/2的,将来可能会直接大年夜浏览器调用基于gRPC的办事,但除非主流的浏览器支撑所需的HTTP/2特点,且谷歌宣布浏览器端的JavaScript gRPC客户端法度榜样,大年夜webapp拜访揣摸办事都应当经由过程办事器端的组件进行。
接下来将基于BaseHTTPServer搭建一个简单的Python Web办事器,BaseHTTPServer将处理上载的图像文件,并将其发送给揣摸办事进行处理,再将揣摸结不雅以纯文本情势返回。
为了将图像发送到揣摸办事器进行分类,办事器将以一个简单的表单对GET请求做出响应。所应用的代码如下:
- From BaseHTTPServer import HTTPServer,BaseHTTPRequestHandler
- import cgi
- import classification_service_pb2
- From grpc.beta import implementations
- class ClientApp (BaseHTTPRequestHandler);
- def do_GET(self):
- self.respond_form()
- def respond_form(self, response=""):
- form = """
- <html><body>
- <h1>Image classification service</h1>
- <form enctype="multipart/form-data" method="post">
- <div>Image: <input type="file" name="file"
- accept="image/jpeg"></div>
- <div><input type="submit" value=http://ai.51cto.com/art/201704/"Upload"></div>
- </form>
- %s
- </body></html>
- """
- response = form % response
- self.send_response(200)
- self.send_header("Content-type", "text/html")
- self.send_header("Content-length", len(response))
- self.end_headers()
- self.wfile.write(response)
为了大年夜Web App办事器调用揣摸功能,须要ClassificationService响应的Python protocol buffer客户端。为了生成它,须要运行Python的protocol buffer编译器:
- pip install grpcio cython grpcio-tools
- python -m grpc.tools.protoc -I. --python_out=. --
推荐阅读
传统的存储厂商正面对着前所未竽暌剐的压力。软件定义存储与公有云存储(也是基于横向扩大的SDS技巧)相浇忧⒛解决筹划正在蚕食传统的存储市场,如Dell EMC的VNX、HPE的Smart Array、NetApp的E系列和FAS。我同样认为>>>详细阅读
本文标题:面向机器智能的TensorFlow实践:产品环境中模型的部署
地址:http://www.17bianji.com/lsqh/34985.html
1/2 1