Arm NN SDK provides a set of tests which can also be considered as demos showing what Arm NN does and how to use it. They load neural network models of various formats (Caffe, TensorFlow, TensorFlow Lite, ONNX), run the inference on a specified input data and output the inference result.
...
cd $BASEDIR/ComputeLibrary/build/examples export LD_LIBRARY_PATH=$BASEDIR/ComputeLibrary/build:$LD_LIBRARY_PATH ./graph_mobilenet_v2
| |
grep "Caff"
| |
...
change the batch size to 1
Original content:
name: "AlexNet" | ||
layer { | ||
name: "data" | ||
type: "Input" | ||
top: "data" | ||
input_param { shape: { dim: 10 dim: 3 dim: 227 dim: 227 } } |
Modified content:
name: "AlexNet" | ||
layer { | ||
name: "data" | ||
type: "Input" | ||
top: "data" | ||
input_param { shape: { dim: 1 dim: 3 dim: 227 dim: 227 } } |
Run the following python script to transform the network
python3
import caffe
net = caffe.Net('deploy.prototxt', 'bvlc_alexnet.caffemodel', caffe.TEST)
new_net = caffe.Net('bvlc_alexnet_1.prototxt', 'bvlc_alexnet.caffemodel', caffe.TEST)
new_net.save('bvlc_alexnet_1.caffemodel')
Copy bvlc_alexnet_1.caffemodel from linux host to ~/ArmnnTests/models in SP7021
...
2.2.2 CaffeInception_BN-Armnn
- Use A linux host with py-caffe installed
Download the model files:
cd ~/ArmnnTests
curl -L -o deploy.prototxt https://raw.githubusercontent.com/pertusa/InceptionBN-21K-for-Caffe/master/deploy.prototxt
curl -L -o Inception21k.caffemodel http://www.dlsi.ua.es/~pertusa/deep/Inception21k.caffemodel
cp deploy.prototxt Inception-BN-batchsize1.prototxt
nano Inception-BN-batchsize1.prototxt
change the batch size to 1
Original content
name: "Inception21k" | ||
layer { | ||
name: "data" | ||
type: "Input" | ||
top: "data" | ||
input_param { shape: { dim: 10 dim: 3 dim: 224 dim: 224 } } |
Modified content:
name: "Inception21k" | ||
layer { | ||
name: "data" | ||
type: "Input" | ||
top: "data" | ||
input_param { shape: { dim: 1 dim: 3 dim: 224 dim: 224 } } |
Run the following python script to transform the network
import caffe
net = caffe.Net('deploy.prototxt', 'Inception21k.caffemodel', caffe.TEST)
new_net = caffe.Net('Inception-BN-batchsize1.prototxt', 'Inception21k.caffemodel', caffe.TEST)
new_net.save(' Inception-BN-batchsize1.caffemodel')python3
Copy Inception-BN-batchsize1.caffemodel to ~/ArmnnTests/models in SP7021
...
2.1.3 CaffeMnist-Armnn
Use A linux host with py-caffe installed
Download the model files:
cd ~/ArmnnTests
curl -L -o lenet.prototxt https://raw.githubusercontent.com/BVLC/caffe/master/examples/mnist/lenet.prototxt
curl -L -o lenet_iter_9000_ori.caffemodel https://github.com/ARM-software/ML-examples/blob/master/armnn-mnist/model/lenet_iter_9000.caffemodel
cp lenet.prototxt lenet_iter_9000.prototxt
nano lenet_iter_9000.prototxt
change the batch size to 1Original content:
name: "LeNet"
layer {
name: "data"
type: "Input"
top: "data"
input_param { shape: { dim: 64 dim: 1 dim: 28 dim: 28 } }
Modified content:
name: "LeNet"
layer {
name: "data"
type: "Input"
top: "data"
input_param { shape: { dim: 1 dim: 1 dim: 28 dim: 28 } }
Run the following python script to transform the network
python3
import caffe
net = caffe.Net(lenet.prototxt', lenet_iter_9000_ori.caffemodel', caffe.TEST)
new_net = caffe.Net(' lenet_iter_9000.prototxt', lenet_iter_9000_ori.caffemodel', caffe.TEST)
new_net.save(' lenet_iter_9000.caffemodel')
Copy lenet_iter_9000.caffemodel to ~/ArmnnTests/models in SP7021- Find a .jpg file containing a shark (great white shark). Rename it to shark.jpg and copy it to the data folder on SP7021.
- Download the two archives below and unpack them:
...
TfInceptionV3-Armnn --data-dir=data --model-dir=models
This is not an execution error. This occurs because the TfInceptionV3-Armnn test expects a specific type of dog, cat and shark to be found so if a different type/breed of these animals is passed to the test, it returns a case failed.
The expected inputs for this test are:
ID | Label | File name |
208 | Golden Retriever | Dog.jpg |
283 | Tiger Cat | Cat.jpg |
3 | White Shark | shark.jpg |
The complete list of supported objects can be found in https://github.com/ARM-software/armnn/blob/branches/armnn_18_11/tests/TfLiteMobilenetQuantized-Armnn/labels.txt
...
3. Python interface to Arm NN (PyArmNN)
For a more complete Arm NN experience, there are examples located in /armnn-pi/armnn/python/pyarmnn/examples/, which require requests, PIL and maybe some other Python3 modules. You may install the missing modules using pip3.
To run these examples you may simply execute them using the Python3 interpreter. There are no arguments and the resources are downloaded by the scripts:
cd ~/armnn-pi/armnn/python/pyarmnn/examples/
python3 tflite_mobilenetv1_quantized.py
python3 onnx_mobilenetv2.py
...