问题描述
我所做的是,我在 Windows 上使用 Docker 部署了张量流服务.我在张量流服务中使用了初始模型.它正在运行.现在,使用 java,我想将图像从浏览器上传到这个在 tensorflow 服务中运行的初始模型,作为响应,我应该获取类名.
What I did is, I have deployed tensor-flow serving using Docker on Windows. I am using inception model inside the tensor-flow serving. It is up and running.Now, using java, I want to upload the image from browser to this inception model running in tensorflow serving and in response I should get the class name.
任何示例都会有所帮助.
Any sample example would help.
推荐答案
假设 Tensorflow Serving 1.11.0-rc1
(在 1.10.1
中不起作用),请求 JSON 负载的形式为:
Assuming Tensorflow Serving 1.11.0-rc1
(it does not work in 1.10.1
), the form of the request JSON payload is:
{
"inputs": {
"images": [{ "b64": "IMAGE_BASE64" }]
}
}
其中 IMAGE_BASE64
是要预测的图像上的 Base64 编码(通常是一个长字符串,因此此处未显示).Java 客户端库需要为输入图像构建此负载.
Where IMAGE_BASE64
is the Base64 encoding on the image to predict on (typically a long string, so not shown here). The Java client library needs to build this payload for an input image.
然后,Java 客户端会将请求提交到以下端点:
Then, the Java client would submit the request to the following endpoint:
POST /v1/models/inception:predict
您可能需要将 inception
替换为部署在服务器上的模型的名称.
You may have to replace inception
for the name of the model deployed on the server.
要从 shell(从运行在 Docker 上的 Linux 或使用等效的 PowerShell 命令)针对 localhost
上可用的服务器进行尝试(映射到 Docker Serving 容器公开的端口,请在此处8501
):
To try from a shell (either from a Linux running on Docker, or with an equivalent PowerShell command) against the server available on localhost
(mapping to the port exposed by your Docker Serving container, here 8501
):
curl -d "@request.json" -X POST http://localhost:8501/v1/models/inception:predict
request.json
文件包含本文开头的请求 JSON 有效负载.典型响应:
The request.json
file contains the request JSON payload at the beginning of this post. A typical response:
{
"outputs": {
"classes": [
"class1",
"class2",
...
],
"scores": [
[
0.0321035,
0.905796,
...
]
]
}
}
重要说明:以上运行来自旧的 Inception v3 模型 (2015) 的部署,在 Serving 0.4.1
时导出.不过,它与 Serving 1.11.0-rc1
一起工作得很好.如果您已使用最新的导出脚本导出模型,则可能存在细微差异(1.11.0-rc1
导出脚本 在签名方面似乎没有区别).所以这个答案可能不适合你,但只是让你走上解决问题的道路.
Important note: The above runs come from a deployment of an old Inception v3 model (2015), exported at the time of Serving 0.4.1
. It works very well with Serving 1.11.0-rc1
, though. If you have exported your model with the latest export script, there might be small differences (the 1.11.0-rc1
export script does not seem to differ in terms of signature). So this answer may not work as is for you, but just put you on the way to solve the problem.
这篇关于使用 Java 客户端使用张量流服务初始模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!