Deep Learning Prediction on ARM Mali GPU
This example shows how to use thecnncodegen
function to generate code for an image classification application that uses deep learning on ARM® Mali GPUs. The example uses theMobileNet-v2
DAG网络执行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 theLD_LIBRARY_PATH
variables are set on the target platform. For information on the supported versions of the compilers and libraries, seeThird-Party Hardware. For setting up the environment variables, seeSetting Up the Prerequisite Products.
Get Pretrained DAGNetwork
Load the pretrainedMobileNet-v2
网络中可用Deep Learning Toolbox Model for MobileNet-v2 Network
.
net = mobilenetv2
网= DAGNetwork属性:1层:[154×nnet.cnn.layer.Layer] Connections: [163×2 table] InputNames: {'input_1'} OutputNames: {'ClassificationLayer_Logits'}
The network contains 155 layers including convolution, batch normalization, softmax, and the classification output layers. TheanalyzeNetwork()
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 thecnncodegen
function, specifying the target library asarm-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 thepscp
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 makefilecnnbuild_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 theputty
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/usrnamearm_mobilenet-fmakefile_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: