SAVE.md 1.4 KB
Newer Older
D
Dong Daxiang 已提交
1 2 3 4 5 6 7 8
## How to save a servable model of Paddle Serving?
- Currently, paddle serving provides a save_model interface for users to access, the interface is similar with `save_inference_model` of Paddle.
``` python
import paddle_serving_client.io as serving_io
serving_io.save_model("imdb_model", "imdb_client_conf",
                      {"words": data}, {"prediction": prediction},
                      fluid.default_main_program())
```
J
Jiawei Wang 已提交
9 10 11 12 13
`imdb_model`是具有服务配置的服务器端模型。 `imdb_client_conf`是客户端rpc配置。 Serving有一个
提供给用户存放`Feed``Fetch`变量信息的字典。 在示例中,`{{words”:data}`是用于指定已保存推理模型输入的提要字典。 `{{"prediction":projection}`是指定保存的推理模型输出的字典。可以为feed和fetch变量定义一个别名。 如何使用别名的例子
示例如下:


D
Dong Daxiang 已提交
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
 ``` python
 from paddle_serving_client import Client
import sys

client = Client()
client.load_client_config(sys.argv[1])
client.connect(["127.0.0.1:9393"])

for line in sys.stdin:
    group = line.strip().split()
    words = [int(x) for x in group[1:int(group[0]) + 1]]
    label = [int(group[-1])]
    feed = {"words": words, "label": label}
    fetch = ["acc", "cost", "prediction"]
    fetch_map = client.predict(feed=feed, fetch=fetch)
    print("{} {}".format(fetch_map["prediction"][1], label[0]))
 ```