Skip to content

Commit 79b1709

Browse files
committed
cal FPS of inference result
1 parent aef6394 commit 79b1709

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

benchmark/paddle/image/provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def initHook(settings, height, width, color, num_class, **kwargs):
2323
@provider(
2424
init_hook=initHook, min_pool_size=-1, cache=CacheType.CACHE_PASS_IN_MEM)
2525
def process(settings, file_list):
26-
for i in xrange(1024):
26+
for i in xrange(2560 if settings.is_infer else 1024):
2727
img = np.random.rand(1, settings.data_size).reshape(-1, 1).flatten()
2828
if settings.is_infer:
2929
yield img.astype('float32')

benchmark/paddle/image/run_mkldnn_infer.sh

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
set -e
22

3+
function clock_to_seconds() {
4+
hours=`echo $1 | awk -F ':' '{print $1}'`
5+
mins=`echo $1 | awk -F ':' '{print $2}'`
6+
secs=`echo $1 | awk -F ':' '{print $3}'`
7+
echo `bc -l <<< "$secs + $mins * 60 + $hours * 3600"`
8+
}
9+
310
function infer() {
411
unset OMP_NUM_THREADS MKL_NUM_THREADS OMP_DYNAMIC KMP_AFFINITY
512
topology=$1
@@ -34,15 +41,26 @@ function infer() {
3441
> /dev/null 2>&1
3542
echo "Done"
3643
fi
44+
log_period=$((256 / bs))
3745
paddle train --job=test \
3846
--config="${topology}.py" \
3947
--use_mkldnn=$use_mkldnn \
4048
--use_gpu=False \
4149
--trainer_count=$thread \
42-
--log_period=32 \
50+
--log_period=$log_period \
4351
--config_args="batch_size=${bs},layer_num=${layer_num},is_infer=True" \
4452
--init_model_path=$models_in \
45-
2>&1 | tee ${log}
53+
2>&1 | tee ${log}
54+
55+
# calculate the last 5 logs period time of 1280 samples,
56+
# the time before are burning time.
57+
start=`tail ${log} -n 7 | head -n 1 | awk -F ' ' '{print $2}' | xargs`
58+
end=`tail ${log} -n 2 | head -n 1 | awk -F ' ' '{print $2}' | xargs`
59+
start_sec=`clock_to_seconds $start`
60+
end_sec=`clock_to_seconds $end`
61+
fps=`bc <<< "scale = 2; 1280 / ($end_sec - $start_sec)"`
62+
echo "Last 1280 samples start: ${start}(${start_sec} sec), end: ${end}(${end_sec} sec;" >> ${log}
63+
echo "FPS: $fps images/sec" >> ${log}
4664
}
4765

4866
if [ ! -f "train.list" ]; then

0 commit comments

Comments
 (0)