Deep Learning Prediction on ARM Mali GPU

This example shows how to use the cnncodegen function to generate code for an image classification application that uses deep learning on ARM® Mali GPUs. The example uses the MobileNet-v2 DAG network to perform image classification. The generated code takes advantage of the ARM Compute library for computer vision and machine learning.

Prerequisites

  • ARM Mali GPU based hardware. For example, HiKey960 is one of the target platforms that contains a Mali GPU.

  • ARM Compute Library on the target ARM hardware built for the Mali GPU.

  • Open source Computer Vision Library (OpenCV v2.4.9) on the target ARM hardware.

  • Environment variables for the compilers and libraries. Ensure that the ARM_COMPUTE and the LD_LIBRARY_PATH variables are set on the target platform. For information on the supported versions of the compilers and libraries, see Third-party Products. For setting up the environment variables, see Setting Up the Prerequisite Products.

  • GPU Coder™ Interface for Deep Learning Libraries support package. To install this support package, use the Add-On Explorer.

Get Pretrained DAGNetwork

Load the pretrained MobileNet-v2 network available in the Deep Learning Toolbox Model for MobileNet-v2 Network.

net = mobilenetv2;

The network contains 155 layers including convolution, batch normalization, softmax, and the classification output layers. The analyzeNetwork() function displays an interactive plot of the network architecture and a table containing information about the network layers.

analyzeNetwork(net);

Generate Code

For deep learning on ARM targets, you generate code on the host development computer. To build and run the executable program, move the generated code to the ARM target platform. The target platform must have an ARM Mali GPU. For example, HiKey960 is one of the target platforms on which you can execute the code generated in this example.

Call the cnncodegen function, specifying the target library as arm-compute-mali.

cnncodegen(net,'targetlib','arm-compute-mali');

Copy Generated Files to the Target

Move the generated codegen folder and other required files from the host development computer to the target platform by using your preferred SCP (Secure Copy Protocol) or Secure Shell File Transfer Protocol (SSH) client.

For example, on the Linux® platform, to transfer the files to the HiKey960, use the scp command with the format:

system('sshpass -p [password] scp (sourcefile) [username]@[targetname]:~/');

system('sshpass -p password scp main_mobilenet_arm_generic.cpp username@targetname:~/');
system('sshpass -p password scp peppers_mobilenet.png username@targetname:~/');
system('sshpass -p password scp makefile_mobilenet_arm_generic.mk username@targetname:~/');
system('sshpass -p password scp synsetWords.txt username@targetname:~/');
system('sshpass -p password scp -r codegen username@targetname:~/');

On the Windows® platform, you can use the pscp tool that comes with a PuTTY installation. For example:

system('pscp -pw password-r codegen username@targetname:/home/username');

PSCP utilities must be either on your PATH or in your current folder.

Build Executable

To build the library on the target platform, use the generated makefile cnnbuild_rtw.mk.

For example, to build the library on the HiKey960:

system('sshpass -p password ssh username@targetname "make -C /home/username/codegen -f cnnbuild_rtw.mk"');

On the Windows platform, you can use the putty command with -ssh argument to log in and run the make command. For example:

system('putty -ssh username@targetname -pw password');

To build and run the executable on the target platform, use the command with the format: make -C /home/$(username) and ./execfile -f makefile_mobilenet_arm_generic.mk

For example, on the HiKey960:

make -C /home/usrname arm_mobilenet -f makefile_mobilenet_arm_generic.mk

Run the executable on the ARM platform specifying an input image file.

./mobilenet_exe peppers_mobilenet.png

The top five predictions for the input image file are:

Copyright 2019 The MathWorks, Inc.