From 34b79406a218f9f78ce350136ee38bb51d077c87 Mon Sep 17 00:00:00 2001 From: Zeyu Date: Mon, 22 Apr 2019 23:16:18 +0800 Subject: [PATCH] add ssd demo --- demo/ssd/README.md | 8 ++-- demo/ssd/{infer.sh => cli_demo.sh} | 0 demo/ssd/infer_by_code.py | 44 ---------------------- demo/ssd/ssd_demo.py | 19 ++++++++++ demo/text-classification/run_classifier.sh | 2 +- 5 files changed, 24 insertions(+), 49 deletions(-) rename demo/ssd/{infer.sh => cli_demo.sh} (100%) delete mode 100644 demo/ssd/infer_by_code.py create mode 100644 demo/ssd/ssd_demo.py diff --git a/demo/ssd/README.md b/demo/ssd/README.md index 0a6aafb2..2b3f5cbc 100644 --- a/demo/ssd/README.md +++ b/demo/ssd/README.md @@ -27,18 +27,18 @@ $ pip install --upgrade paddlepaddle ## 命令行方式预测 -`infer.sh`给出了使用命令行调用Module预测的示例脚本 +`cli_demo.sh`给出了使用命令行调用Module预测的示例脚本 通过以下命令试验下效果 ```shell -$ sh infer.sh +$ sh cli_demo.sh ``` ## 通过python API预测 -`infer_by_code.py`给出了使用python API调用Module预测的示例代码 +`ssd_demo.py`给出了使用python API调用Module预测的示例代码 通过以下命令试验下效果 ```shell -python infer_by_code.py +python ssd_demo.py ``` diff --git a/demo/ssd/infer.sh b/demo/ssd/cli_demo.sh similarity index 100% rename from demo/ssd/infer.sh rename to demo/ssd/cli_demo.sh diff --git a/demo/ssd/infer_by_code.py b/demo/ssd/infer_by_code.py deleted file mode 100644 index 10e65bb2..00000000 --- a/demo/ssd/infer_by_code.py +++ /dev/null @@ -1,44 +0,0 @@ -import os -import paddlehub as hub - - -def infer_with_input_path(): - # get ssd module - ssd = hub.Module(name="ssd_mobilenet_v1_pascal") - - test_img_path = os.path.join("test", "test_img_bird.jpg") - - # get the input keys for signature 'object_detection' - data_format = ssd.processor.data_format(sign_name='object_detection') - key = list(data_format.keys())[0] - - # set input dict - input_dict = {key: [test_img_path]} - - # execute predict and print the result - results = ssd.object_detection(data=input_dict) - for result in results: - hub.logger.info(result) - - -def infer_with_input_file(): - # get ssd module - ssd = hub.Module(name="ssd_mobilenet_v1_pascal") - - # get the input keys for signature 'object_detection' - data_format = ssd.processor.data_format(sign_name='object_detection') - key = list(data_format.keys())[0] - - # parse input file - test_file = os.path.join("test", "test.txt") - test_images = hub.io.parser.txt_parser.parse(test_file) - - # set input dict - input_dict = {key: test_images} - results = ssd.object_detection(data=input_dict) - for result in results: - hub.logger.info(result) - - -if __name__ == "__main__": - infer_with_input_file() diff --git a/demo/ssd/ssd_demo.py b/demo/ssd/ssd_demo.py new file mode 100644 index 00000000..4a24751f --- /dev/null +++ b/demo/ssd/ssd_demo.py @@ -0,0 +1,19 @@ +import os +import paddlehub as hub + +if __name__ == "__main__": + ssd = hub.Module(name="ssd_mobilenet_v1_pascal") + + test_img_path = os.path.join("test", "test_img_bird.jpg") + + # get the input keys for signature 'object_detection' + data_format = ssd.processor.data_format(sign_name='object_detection') + key = list(data_format.keys())[0] + + # set input dict + input_dict = {key: [test_img_path]} + + # execute predict and print the result + results = ssd.object_detection(data=input_dict) + for result in results: + hub.logger.info(result) diff --git a/demo/text-classification/run_classifier.sh b/demo/text-classification/run_classifier.sh index 0b53a268..cb80a788 100644 --- a/demo/text-classification/run_classifier.sh +++ b/demo/text-classification/run_classifier.sh @@ -10,7 +10,7 @@ CKPT_DIR="./ckpt_${DATASET}" python -u text_classifier.py \ --batch_size=24 \ - --use_gpu=True \ + --use_gpu=False \ --dataset=${DATASET} \ --checkpoint_dir=${CKPT_DIR} \ --learning_rate=5e-5 \ -- GitLab