Getting started with AI on NXP i.MX8M Plus - Neural Processing Unit - Use Case experiments: Smart Parking - Bash scripts for CPU usage and time estimation
< Getting started with AI on NXP i.MX8M Plus | Neural Processing Unit/Use Case experiments: Smart Parking
Getting started with AI on NXP i.MX8M Plus RidgeRun documentation is currently under development. |
|
Parallel experiment scripts
The following scripts were useful for profiling the performance of Rosetta and TinyYOLO v3 sharing resources on the i.MX8M Plus. These prototypes were developed in C++ before giving the support in the GStreamer wrapper GstInference and R2Inference. Even though the code of the prototype is not available these scripts may help people to profile their applications when parallel execution is needed.
Execution time estimation script
The execution time was taken using the C++ STL High-Precision clock inside the C++ prototype.
# This test is intended to run in parallel two inferences and log
# the performance in time terms.
# Variables for TinyYOLO
TY_INPUT_IMAGE=/car_plate_detection/G1.jpg
TY_OUTPUT_IMAGE=/car_plate_detection/G12.jpg
TY_MODEL=/car_plate_detection/car_plate_tinyYolo_model2.tflite
TY_WR_LOOPS=100
TY_DL=2
TY_THREADS=4
# Variables for Rosetta:
car_plate_recognition
R_INPUT_IMAGE=/car_plate_recognition/prueba.png
R_OUTPUT_IMAGE=/car_plate_recognition/prueba2.png
R_MODEL=/car_plate_recognition/crnn_dr.tflite
R_WR_LOOPS=100
R_DL=3
R_THREADS=4
# TinyYOLO inference
./car_plate_detection/test_TinyYOLO $TY_INPUT_IMAGE $TY_OUTPUT_IMAGE $TY_MODEL $TY_WR_LOOPS $TY_DL $TY_THREADS &
TY=$!
# Rosetta inference:
./car_plate_recognition/test_Rosetta $R_INPUT_IMAGE $R_OUTPUT_IMAGE $R_MODEL $R_WR_LOOPS $R_DL $R_THREADS &
RT=$!
wait $TY $RT
echo "----------------------------Done------------------------------"
CPU usage estimation script
The CPU usage was taken from this script using the PS Linux command
# This script is intended to check the CPU usage
# for processes related to TinyYOLO inference and
# Rosetta inference.
# Every 1 second, the script will sample the CPU usage
# for both inferences. So 900s/60s = 15min. Which means
# that for 15 minutes this script will be logging
# the CPU usage.
DURATION=900
TINYYOLO_USAGE=0
YOLO_PREFIX="test_TinyYOLO"
YOLO_RESULTS_TXT="TinyYOLO_CPU_usage.txt"
ROSETTA_USAGE=0
ROSETTA_PREFIX="test_Rosetta"
ROSETTA_RESULTS_TXT="Rosetta_CPU_usage.txt"
for counter in {0..900..1}
do
TINYYOLO_USAGE=$(ps -eocomm,pcpu | egrep -v '(0.0)|(%CPU)' | grep test_TinyYOLO)
ROSETTA_USAGE=$(ps -eocomm,pcpu | egrep -v '(0.0)|(%CPU)' | grep test_Rosetta)
if [ -z "$TINYYOLO_USAGE" ]
then
echo "tinyYOLO usage: $counter, 0"
echo "($counter, 0)" >> $YOLO_RESULTS_TXT
else
echo "tinyYOLO usage: $counter, ${TINYYOLO_USAGE/#$YOLO_PREFIX}"
echo "($counter, ${TINYYOLO_USAGE/#$YOLO_PREFIX})" >> $YOLO_RESULTS_TXT
fi
if [ -z "$ROSETTA_USAGE" ]
then
echo "rosetta usage : $counter, 0"
echo "($counter, 0)" >> $ROSETTA_RESULTS_TXT
else
echo "rosetta usage : $counter, ${ROSETTA_USAGE/#$ROSETTA_PREFIX}"
echo "($counter, ${ROSETTA_USAGE/#$ROSETTA_PREFIX})" >> $ROSETTA_RESULTS_TXT
fi
sleep 1
done