Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into feature/combine_open_files_and_double_buffer
commit
be528f9815
@ -1,59 +0,0 @@
|
||||
# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
option(WITH_INFERENCE_DEMO "Compile with Inference demo" OFF)
|
||||
if(NOT WITH_INFERENCE_DEMO)
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(DEMO_INSTALL_DIR "${PADDLE_BINARY_DIR}/inference_demo")
|
||||
set(URL_ROOT http://paddlemodels.bj.bcebos.com/inference-vis-demos%2F)
|
||||
|
||||
function(inference_download_test_demo TARGET)
|
||||
if (NOT WITH_TESTING)
|
||||
return()
|
||||
endif()
|
||||
set(options "")
|
||||
set(oneValueArgs URL)
|
||||
set(multiValueArgs SRCS)
|
||||
cmake_parse_arguments(tests "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||
|
||||
set(test_dir "${DEMO_INSTALL_DIR}/${TARGET}")
|
||||
message(STATUS "inference demo ${test_dir}")
|
||||
|
||||
if(NOT EXISTS "${test_dir}")
|
||||
message(STATUS "Download ${TARGET} model from ${tests_URL}")
|
||||
execute_process(COMMAND bash -c "mkdir -p ${test_dir}")
|
||||
execute_process(COMMAND bash -c "cd ${test_dir}; wget -q ${tests_URL}")
|
||||
execute_process(COMMAND bash -c "cd ${test_dir}; tar xzf *.tar.gz")
|
||||
endif()
|
||||
|
||||
cc_test(${TARGET} SRCS "${tests_SRCS}"
|
||||
DEPS paddle_inference_api paddle_fluid
|
||||
ARGS --data=${test_dir}/data.txt
|
||||
--modeldir=${test_dir}/model
|
||||
--refer=${test_dir}/result.txt)
|
||||
endfunction()
|
||||
|
||||
# disable mobilenet test
|
||||
#inference_download_test_demo(mobilenet_inference_demo
|
||||
# SRCS vis_demo.cc
|
||||
# URL ${URL_ROOT}mobilenet.tar.gz)
|
||||
inference_download_test_demo(se_resnext50_inference_demo
|
||||
SRCS vis_demo.cc
|
||||
URL ${URL_ROOT}se_resnext50.tar.gz)
|
||||
inference_download_test_demo(ocr_inference_demo
|
||||
SRCS vis_demo.cc
|
||||
URL ${URL_ROOT}ocr.tar.gz)
|
@ -1,36 +0,0 @@
|
||||
# Infernce Demos
|
||||
|
||||
Input data format:
|
||||
|
||||
- Each line contains a single record
|
||||
- Each record's format is
|
||||
|
||||
```
|
||||
<space splitted floats as data>\t<space splitted ints as shape>
|
||||
```
|
||||
|
||||
Follow the C++ codes in `vis_demo.cc`.
|
||||
|
||||
## MobileNet
|
||||
|
||||
To execute the demo, simply run
|
||||
|
||||
```sh
|
||||
./mobilenet_inference_demo --modeldir <model> --data <datafile>
|
||||
```
|
||||
|
||||
## SE-ResNeXt-50
|
||||
|
||||
To execute the demo, simply run
|
||||
|
||||
```sh
|
||||
./se_resnext50_inference_demo --modeldir <model> --data <datafile>
|
||||
```
|
||||
|
||||
## OCR
|
||||
|
||||
To execute the demo, simply run
|
||||
|
||||
```sh
|
||||
./ocr_inference_demo --modeldir <model> --data <datafile>
|
||||
```
|
@ -0,0 +1 @@
|
||||
data
|
@ -0,0 +1,26 @@
|
||||
# Inference Demos
|
||||
|
||||
There are several demos:
|
||||
|
||||
- simple_on_word2vec:
|
||||
- Follow the C++ codes is in `simple_on_word2vec.cc`.
|
||||
- It is suitable for word2vec model.
|
||||
- vis_demo:
|
||||
- Follow the C++ codes is in `vis_demo.cc`.
|
||||
- It is suitable for mobilenet, se_resnext50 and ocr three models.
|
||||
- Input data format:
|
||||
- Each line contains a single record
|
||||
- Each record's format is
|
||||
```
|
||||
<space splitted floats as data>\t<space splitted ints as shape>
|
||||
```
|
||||
|
||||
To build and execute the demos, simply run
|
||||
```
|
||||
./run.sh $PADDLE_ROOT $TURN_ON_MKL $TEST_GPU_CPU
|
||||
```
|
||||
- It will build and execute the demos in both static and shared library.
|
||||
- `$PADDLE_ROOT`: paddle library path
|
||||
- `$TURN_ON_MKL`: use MKL or Openblas
|
||||
- `$TEST_GPU_CPU`: test both GPU/CPU mode or only CPU mode
|
||||
- NOTE: for simple_on_word2vec, must run `ctest -R test_word2vec -R` to obtain word2vec model at first.
|
@ -1,34 +1,81 @@
|
||||
set -x
|
||||
PADDLE_ROOT=$1
|
||||
WITH_MKL=$2
|
||||
WITH_GPU=$3
|
||||
if [ $3 == "ON" ]; then
|
||||
TURN_ON_MKL=$2 # use MKL or Openblas
|
||||
TEST_GPU_CPU=$3 # test both GPU/CPU mode or only CPU mode
|
||||
if [ $2 == ON ]; then
|
||||
# You can export yourself if move the install path
|
||||
MKL_LIB=${PADDLE_ROOT}/build/fluid_install_dir/third_party/install/mklml/lib
|
||||
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${MKL_LIB}
|
||||
fi
|
||||
if [ $3 == ON ]; then
|
||||
use_gpu_list='true false'
|
||||
else
|
||||
use_gpu_list='false'
|
||||
fi
|
||||
|
||||
# download vis_demo data
|
||||
function download() {
|
||||
dir_name=$1
|
||||
mkdir -p $dir_name
|
||||
cd $dir_name
|
||||
wget -q ${URL_ROOT}$dir_name.tar.gz
|
||||
tar xzf *.tar.gz
|
||||
cd ..
|
||||
}
|
||||
URL_ROOT=http://paddlemodels.bj.bcebos.com/inference-vis-demos%2F
|
||||
mkdir -p data
|
||||
cd data
|
||||
vis_demo_list='se_resnext50 ocr mobilenet'
|
||||
for vis_demo_name in $vis_demo_list; do
|
||||
download $vis_demo_name
|
||||
done
|
||||
cd ..
|
||||
|
||||
# compile and test the demo
|
||||
mkdir -p build
|
||||
cd build
|
||||
|
||||
for WITH_STATIC_LIB in false; do
|
||||
for WITH_STATIC_LIB in ON OFF; do
|
||||
# -----simple_on_word2vec-----
|
||||
rm -rf *
|
||||
cmake .. -DPADDLE_LIB=${PADDLE_ROOT}/build/fluid_install_dir/ \
|
||||
-DWITH_MKL=$WITH_MKL \
|
||||
-DWITH_MKL=$TURN_ON_MKL \
|
||||
-DDEMO_NAME=simple_on_word2vec \
|
||||
-DWITH_GPU=$WITH_GPU \
|
||||
-DWITH_GPU=$TEST_GPU_CPU \
|
||||
-DWITH_STATIC_LIB=$WITH_STATIC_LIB
|
||||
make
|
||||
for use_gpu in $use_gpu_list; do
|
||||
./simple_on_word2vec \
|
||||
--dirname=${PADDLE_ROOT}/build/python/paddle/fluid/tests/book/word2vec.inference.model \
|
||||
--use_gpu=$use_gpu
|
||||
make -j
|
||||
word2vec_model=${PADDLE_ROOT}'/build/python/paddle/fluid/tests/book/word2vec.inference.model'
|
||||
if [ -d $word2vec_model ]; then
|
||||
for use_gpu in $use_gpu_list; do
|
||||
./simple_on_word2vec \
|
||||
--dirname=$word2vec_model \
|
||||
--use_gpu=$use_gpu
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "simple_on_word2vec demo runs fail."
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
fi
|
||||
# ---------vis_demo---------
|
||||
rm -rf *
|
||||
cmake .. -DPADDLE_LIB=${PADDLE_ROOT}/build/fluid_install_dir/ \
|
||||
-DWITH_MKL=$TURN_ON_MKL \
|
||||
-DDEMO_NAME=vis_demo \
|
||||
-DWITH_GPU=$TEST_GPU_CPU \
|
||||
-DWITH_STATIC_LIB=$WITH_STATIC_LIB
|
||||
make -j
|
||||
for use_gpu in false; do
|
||||
for vis_demo_name in $vis_demo_list; do
|
||||
./vis_demo \
|
||||
--modeldir=../data/$vis_demo_name/model \
|
||||
--data=../data/$vis_demo_name/data.txt \
|
||||
--refer=../data/$vis_demo_name/result.txt \
|
||||
--use_gpu=$use_gpu
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "vis demo $vis_demo_name runs fail."
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
done
|
||||
done
|
||||
if [ $? -eq 0 ]; then
|
||||
exit 0
|
||||
else
|
||||
echo "inference demo runs fail."
|
||||
exit 1
|
||||
fi
|
||||
set +x
|
||||
|
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue