diff --git a/doc/BERT_10_MINS.md b/doc/BERT_10_MINS.md index 7a778558b34bba7f4e65ba729155493ea1a3b7c3..706c14bb116beca04eca94c27cc4f15f424ef0de 100644 --- a/doc/BERT_10_MINS.md +++ b/doc/BERT_10_MINS.md @@ -13,10 +13,10 @@ module = hub.Module(model_name) inputs, outputs, program = module.context( trainable=True, max_seq_len=20) feed_keys = ["input_ids", "position_ids", "segment_ids", - "input_mask", "pooled_output", "sequence_output"] + "input_mask"] fetch_keys = ["pooled_output", "sequence_output"] feed_dict = dict(zip(feed_keys, [inputs[x] for x in feed_keys])) -fetch_dict = dict(zip(fetch_keys, [outputs[x]] for x in fetch_keys)) +fetch_dict = dict(zip(fetch_keys, [outputs[x] for x in fetch_keys])) import paddle_serving_client.io as serving_io serving_io.save_model("bert_seq20_model", "bert_seq20_client", diff --git a/python/examples/bert/README.md b/python/examples/bert/README.md index 9c0172a3a1bbf729335ac2f219f5b05fd0bea92a..612ba8beb979f5a1ee9d1a8052f73169191f4fd7 100644 --- a/python/examples/bert/README.md +++ b/python/examples/bert/README.md @@ -5,12 +5,17 @@ ### 获取模型 示例中采用[Paddlehub](https://github.com/PaddlePaddle/PaddleHub)中的[BERT中文模型](https://www.paddlepaddle.org.cn/hubdetail?name=bert_chinese_L-12_H-768_A-12&en_category=SemanticModel)。 +请先安装paddlehub +``` +pip install paddlehub +``` 执行 ``` -python prepare_model.py +python prepare_model.py 20 ``` -生成server端配置文件与模型文件,存放在serving_server_model文件夹 -生成client端配置文件,存放在serving_client_conf文件夹 +参数20表示BERT模型中的max_seq_len,即预处理后的样本长度。 +生成server端配置文件与模型文件,存放在bert_seq20_model文件夹 +生成client端配置文件,存放在bert_seq20_client文件夹 ### 获取词典和样例数据 @@ -22,19 +27,24 @@ sh get_data.sh ### 启动RPC预测服务 执行 ``` -python -m paddle_serving_server.serve --model serving_server_model/ --port 9292 #启动cpu预测服务 +python -m paddle_serving_server.serve --model bert_seq20_model/ --port 9292 #启动cpu预测服务 ``` 或者 ``` -python -m paddle_serving_server_gpu.serve --model serving_server_model/ --port 9292 --gpu_ids 0 #在gpu 0上启动gpu预测服务 +python -m paddle_serving_server_gpu.serve --model bert_seq20_model/ --port 9292 --gpu_ids 0 #在gpu 0上启动gpu预测服务 ``` ### 执行预测 +执行预测前需要安装paddle_serving_app,模块中提供了BERT模型的数据预处理方法。 +``` +pip install paddle_serving_app +``` +执行 ``` -python bert_rpc_client.py --thread 4 +cat data-c.txt | python bert_client.py ``` -启动client读取data-c.txt中的数据进行预测,--thread参数控制client的进程数,预测结束后会打印出每个进程的耗时,server端的地址在脚本中修改。 +启动client读取data-c.txt中的数据进行预测,预测结果为文本的向量表示(由于数据较多,脚本中没有将输出进行打印),server端的地址在脚本中修改。 ### 启动HTTP预测服务 ``` @@ -42,7 +52,7 @@ python bert_rpc_client.py --thread 4 ``` 通过环境变量指定gpu预测服务使用的gpu,示例中指定索引为0和1的两块gpu ``` - python bert_web_service.py serving_server_model/ 9292 #启动gpu预测服务 + python bert_web_service.py bert_seq20_model/ 9292 #启动gpu预测服务 ``` ### 执行预测 diff --git a/python/examples/bert/bert_client.py b/python/examples/bert/bert_client.py index 91323bc1d309206d54451b322bc312b6f07c382a..cceb07c7334aa0cc9b9c347ae53351b7a6fa3513 100644 --- a/python/examples/bert/bert_client.py +++ b/python/examples/bert/bert_client.py @@ -25,12 +25,13 @@ from paddlehub.common.logger import logger import socket from paddle_serving_client import Client from paddle_serving_client.utils import benchmark_args +from paddle_serving_app import ChineseBertReader + args = benchmark_args() -fin = open("data-c.txt") -reader = BertReader(vocab_file="vocab.txt", max_seq_len=128) +reader = ChineseBertReader(max_seq_len=20) fetch = ["pooled_output"] -endpoint_list = ["127.0.0.1:9494"] +endpoint_list = ["127.0.0.1:9292"] client = Client() client.load_client_config(args.model) client.connect(endpoint_list) diff --git a/python/examples/criteo_ctr/README.md b/python/examples/criteo_ctr/README.md index 522bd14bf5e3d600e8d045fa2b02c429223ae7ca..e59947ba377160fe0dc1d1105f35c467e50d32ad 100644 --- a/python/examples/criteo_ctr/README.md +++ b/python/examples/criteo_ctr/README.md @@ -14,7 +14,8 @@ python local_train.py ### 启动RPC预测服务 ``` -python -m paddle_serving_server.serve --model ctr_serving_model/ --port 9292 +python -m paddle_serving_server.serve --model ctr_serving_model/ --port 9292 #启动CPU预测服务 +python -m paddle_serving_server_gpu.serve --model ctr_serving_model/ --port 9292 --gpu_ids 0 #在GPU 0上启动预测服务 ``` ### 执行预测 @@ -22,3 +23,4 @@ python -m paddle_serving_server.serve --model ctr_serving_model/ --port 9292 ``` python test_client.py ctr_client_conf/serving_client_conf.prototxt raw_data/ ``` +预测完毕会输出预测过程的耗时。 diff --git a/python/examples/imagenet/README.md b/python/examples/imagenet/README.md index 5c1b03e78cae1d186fb807ea9b40db32dc77e554..1c4cdd3634157d1de91eda85dc9750592d2d86eb 100644 --- a/python/examples/imagenet/README.md +++ b/python/examples/imagenet/README.md @@ -34,6 +34,6 @@ python -m paddle_serving_server_gpu.serve --model ResNet50_vd_model --port 9393 client端进行预测 ``` -python image_rpc_client.py conf_and_model/serving_client_conf/serving_client_conf.prototxt +python image_rpc_client.py ResNet50_vd_client_config/serving_client_conf.prototxt ``` *server端示例中服务端口为9393端口,client端示例中数据来自./data文件夹,server端地址为本地9393端口,可根据实际情况更改脚本。* diff --git a/python/examples/imagenet/get_model.sh b/python/examples/imagenet/get_model.sh index 88f9f589e32493613d9db0f837d5b4592b194d42..e017cc5101771c30f0c83e17f203ac5bff8d8570 100644 --- a/python/examples/imagenet/get_model.sh +++ b/python/examples/imagenet/get_model.sh @@ -4,4 +4,4 @@ wget --no-check-certificate https://paddle-serving.bj.bcebos.com/imagenet-exampl tar -xzvf ResNet101_vd.tar.gz wget --no-check-certificate https://paddle-serving.bj.bcebos.com/imagenet-example/image_data.tar.gz -tar -xzvf imgae_data.tar.gz +tar -xzvf image_data.tar.gz diff --git a/python/examples/imdb/README.md b/python/examples/imdb/README.md index c7de4a83212a559410e7053582d92d497168b4d3..438ec85932124d0ac8f146522d0f29e54f7170ec 100644 --- a/python/examples/imdb/README.md +++ b/python/examples/imdb/README.md @@ -11,11 +11,11 @@ sh get_data.sh ### 启动RPC预测服务 ``` -python -m paddle_serving_server.serve --model imdb_bow_model/ --port 9292 +python -m paddle_serving_server.serve --model imdb_cnn_model/ --port 9292 ``` ### 执行预测 ``` -head test_data/part-0 | python test_client.py imdb_lstm_client_conf/serving_client_conf.prototxt imdb.vocab +head test_data/part-0 | python test_client.py imdb_cnn_client_conf/serving_client_conf.prototxt imdb.vocab ``` 预测test_data/part-0的前十个样例。