From 79b17097f65a0c6a0b25eb7385b423c01129f003 Mon Sep 17 00:00:00 2001 From: tensor-tang Date: Fri, 1 Dec 2017 00:27:43 +0800 Subject: [PATCH] cal FPS of inference result --- benchmark/paddle/image/provider.py | 2 +- benchmark/paddle/image/run_mkldnn_infer.sh | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/benchmark/paddle/image/provider.py b/benchmark/paddle/image/provider.py index a3a6b6fc4d1..927b1759941 100644 --- a/benchmark/paddle/image/provider.py +++ b/benchmark/paddle/image/provider.py @@ -23,7 +23,7 @@ def initHook(settings, height, width, color, num_class, **kwargs): @provider( init_hook=initHook, min_pool_size=-1, cache=CacheType.CACHE_PASS_IN_MEM) def process(settings, file_list): - for i in xrange(1024): + for i in xrange(2560 if settings.is_infer else 1024): img = np.random.rand(1, settings.data_size).reshape(-1, 1).flatten() if settings.is_infer: yield img.astype('float32') diff --git a/benchmark/paddle/image/run_mkldnn_infer.sh b/benchmark/paddle/image/run_mkldnn_infer.sh index 3081d5e7b54..03a76c05400 100755 --- a/benchmark/paddle/image/run_mkldnn_infer.sh +++ b/benchmark/paddle/image/run_mkldnn_infer.sh @@ -1,5 +1,12 @@ set -e +function clock_to_seconds() { + hours=`echo $1 | awk -F ':' '{print $1}'` + mins=`echo $1 | awk -F ':' '{print $2}'` + secs=`echo $1 | awk -F ':' '{print $3}'` + echo `bc -l <<< "$secs + $mins * 60 + $hours * 3600"` +} + function infer() { unset OMP_NUM_THREADS MKL_NUM_THREADS OMP_DYNAMIC KMP_AFFINITY topology=$1 @@ -34,15 +41,26 @@ function infer() { > /dev/null 2>&1 echo "Done" fi + log_period=$((256 / bs)) paddle train --job=test \ --config="${topology}.py" \ --use_mkldnn=$use_mkldnn \ --use_gpu=False \ --trainer_count=$thread \ - --log_period=32 \ + --log_period=$log_period \ --config_args="batch_size=${bs},layer_num=${layer_num},is_infer=True" \ --init_model_path=$models_in \ - 2>&1 | tee ${log} + 2>&1 | tee ${log} + + # calculate the last 5 logs period time of 1280 samples, + # the time before are burning time. + start=`tail ${log} -n 7 | head -n 1 | awk -F ' ' '{print $2}' | xargs` + end=`tail ${log} -n 2 | head -n 1 | awk -F ' ' '{print $2}' | xargs` + start_sec=`clock_to_seconds $start` + end_sec=`clock_to_seconds $end` + fps=`bc <<< "scale = 2; 1280 / ($end_sec - $start_sec)"` + echo "Last 1280 samples start: ${start}(${start_sec} sec), end: ${end}(${end_sec} sec;" >> ${log} + echo "FPS: $fps images/sec" >> ${log} } if [ ! -f "train.list" ]; then -- GitLab