Introduction

The Qualcomm® Neural Processing SDK for artificial intelligence (AI) (the SDK) allows developers to convert neural network models trained in Caffe/Caffe2, ONNX, or TensorFlow and run them optimally on Snapdragon® mobile platforms.

Below, we show you how to set up the SDK and use it to build your first working app.

Legal Disclaimer:Your use of this guide, including but not limited to the instructions, steps, and commands below, is subject to the Website Terms of Use and may contain references to third party or open source software that is not distributed by Qualcomm Technologies, Inc. or its affiliates. You are solely responsible for the installation, configuration, and use of any such third party or open source software and compliance with any applicable licenses. 

System Requirements

The following dependencies are required to use the SDK:

Set up the Qualcomm Neural Processing SDK for AI

This step allows the SDK to work with the Caffe, TensorFlow, ONNX, and TensorFlow Lite frameworks via Python APIs. Follow the steps below to set up the SDK on Ubuntu 18.04:

  1. Download the latest version of the SDK.
  2. Unpack the SDK’s .zip file to an appropriate location (e.g., ~/snpe-sdk).
  3. Install the SDK’s dependencies:sudo apt-get install python3-dev python3-matplotlib python3-numpy python3-protobuf python3-scipy python3-skimage python3-sphinx wget zip
  4. Verify that all dependencies are installed:~/snpe-sdk/bin/dependencies.sh
  5. Verify that the Python dependencies are installed:source ~/snpe-sdk/bin/check_python_depends.sh
  6. Initialize the Qualcomm Neural Processing SDK environment:cd ~/snpe-sdk/
    export ANDROID_NDK_ROOT=~/Android/Sdk/ndk-bundle

    Note: set ANDROID_NDK_ROOT to the location of your Android Studio installation.

  7. Set up your SDK’s environment based on your chosen ML framework:

    Environment Setup for Caffe
    Navigate to $SNPE_ROOT and run the following script to set up the SDK’s environment for Caffe:source bin/envsetup.sh -c $CAFFE_DIRwhere $CAFFE_DIR is the path to the Caffe installation.


    The script may show warnings about a mismatched Caffe SHA. The SHA that the script checks for is the SHA that the SDK has been tested with. It is ok to use a different version of Caffe, including a version built from source, so this warning can be ignored.


    Environment Setup for Caffe2
    Navigate to $SNPE_ROOT and run the following script to set up the SDK’s environment for Caffe2:source bin/envsetup.sh -f $CAFFE2_DIRwhere $CAFFE2_DIR is the path to the Caffe2 installation.


    Environment Setup for TensorFlow
    Navigate to $SNPE_ROOT and run the following script to set up the SDK’s environment for TensorFlow:source bin/envsetup.sh -t $TENSORFLOW_DIRwhere $TENSORFLOW_DIR is the path to the TensorFlow installation.


    Environment Setup for ONNX
    Navigate to $SNPE_ROOT and run the following script to set up the SDK’s environment for ONNX:source bin/envsetup.sh -o $ONNX_DIRwhere $ONNX_DIR is the path to the ONNX installation.


    Environment Setup for TensorFlow Lite
    Navigate to $SNPE_ROOT and run the following script to set up the SDK’s environment for TensorFlow Lite:

    source bin/envsetup.sh

    The initialization will do the following:

    • Update $SNPE_ROOT, $PATH, $LD_LIBRARY_PATH, $PYTHONPATH, $CAFFE_DIR, $CAFFE2_DIR, $TENSORFLOW_DIR, or $ONNX_DIR
    • Copy the Android NDK libgnustl_shared.so library locally
    • Update the Android AAR archive

Download ML Models and Convert them to .dlc Format

The Qualcomm Neural Processing SDK for AI does not bundle any model files but contains scripts to download some popular publicly-available models and convert them to Qualcomm Technoloiges’ proprietary Deep Learning Container (.dlc) format. Follow the steps below to use these scripts:

  1. Run the following commands to download and convert a pre-trained AlexNet example in Caffe format:cd $SNPE_ROOT
    python ./models/alexnet/scripts/setup_alexnet.py -a ./temp-assets-cache -d
    Tip: take a look at the setup_alexnet.py script, which performs the conversion to DLC. You will likely perform the same operations for your Caffe model conversion.

  2. Run the following commands to download and convert a pre-trained inception_v3 example in TensorFlow format:cd $SNPE_ROOT
    python ./models/inception_v3/scripts/setup_inceptionv3.py -a ./temp-assets-cache -d
    Tip: take a look at the setup_inceptionv3.py script, which also performs quantization on the model to reduce its size by almost 75% (91MB down to 23MB).

Build the SDK’s Example Android App

The Qualcomm Neural Processing SDK for AI includes an example Android app that combines the Snapdragon NPE runtime (provided by the /android/snpe-release.aar Android library) and the DLC model generated by the Caffe AlexNet example described above.

Follow the steps below to build this example app:

  1. Run the following commands to prepare the app by copying the runtime and the model:cd $SNPE_ROOT/examples/android/image-classifiers
    cp ../../../android/snpe-release.aar ./app/libs # copies the NPE runtime library
    bash ./setup_models.sh # packages the Alexnet example (DLC, labels, imputs) as an Android resource file

  2. Choose one of the following options to build the APK:
    Option A: Build the APK in Android Studio:
    1. Launch Android Studio.
    2. Open the project in ~/snpe-sdk/examples/android/image-classifiers.
    3. Accept the Android Studio suggestions to upgrade the build system components, if offered.
    4. Click Run app button to build and run the APK.

    Option B: Execute the following command to build the APK from the command line:
    sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386
    ./gradlew assembleDebug


    Note: The command above will likely require ANDROID_HOME and JAVA_HOME to be set to the location of the Android SDK and the JRE/JDK in your system.

Snapdragon and Qualcomm Neural Processing SDK are products of Qualcomm Technologies, Inc. and/or its subsidiaries.