Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ravi9/97425120a2bc2a2c62c1e669f7cff544 to your computer and use it in GitHub Desktop.
Save ravi9/97425120a2bc2a2c62c1e669f7cff544 to your computer and use it in GitHub Desktop.
Intel TensorFlow CNN Benchmarking Script
# !/bin/bash
# Run TensorFlow's tf_cnn benchmarks in tensorflow_p36 virtualenv
# Activate TensorFlow virtual environment
#source activate tensorflow_p36
# Clone benchmark scripts
git clone https://github.com/tensorflow/benchmarks.git
cd benchmarks/scripts/tf_cnn_benchmarks/
#rm *.log # remove logs from any previous benchmark runs
# Assign num_cores to the number of physical cores on your machine
num_cores=36
# Set environment variables
export KMP_AFFINITY=granularity=fine,verbose,compact,1,0
export KMP_BLOCKTIME=1
export KMP_SETTINGS=1
export OMP_NUM_THREADS=$num_cores
export OMP_PROC_BIND=true
## Run training benchmark scripts
#networks=( alexnet googlenet inception3 resnet50 resnet152 vgg16 )
networks=( googlenet inception3 resnet50 resnet152 vgg16 )
batch_sizes=( 1 32 64 96 128 )
for network in "${networks[@]}" ; do
for bs in "${batch_sizes[@]}"; do
echo -e "\n\n #### Starting $network with batch size = $bs ####\n\n"
# Run Inference benchmark, please note the data format is NCHW is optimized for MKL
time python tf_cnn_benchmarks.py --data_format NCHW --model $network --batch_size $bs --num_batches 30 \
--num_intra_threads $num_cores --num_inter_threads 1 --forward_only=True \
2>&1 | tee net_"$network"_bs_"$bs".log
done
done
## Print training benchmark throughput
echo -e "\n Network batch_size images/second \n"
for network in "${networks[@]}" ; do
for bs in "${batch_sizes[@]}"; do
fps=$(grep "total images/sec:" net_"$network"_bs_"$bs".log | cut -d ":" -f2 | xargs)
echo "$network $bs $fps"
done
echo -e "\n"
done
# Deactivate virtual environment
#source deactivate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment