Enviroment Setup for Qualcomm's Neural processing SDK

Pre-requisite :-

  • A workstation running x86_64 Linux for DLC preparation, generation, and quantization.
  • Ubuntu 20.04 (either in a native OS environment or through WSL2 on Windows 10/11).
  • Model should be in One of the following frameworks:

  1. TensorFlow
  2. ONNX
  3. PyTorch
  4. TensorFlow Lite 

  • Model training must be complete. 
  •  The Android developer’s toolkit (NDK) is required.
  •  Python v2.7 or later is required. 
  •  Android SDK platform tools are required. 
  •  The Android debug bridge (adb) must be installed.

Here we will discuss the steps to setup the Environment for Qualcomm Neural processing SDK :- 

step I :- Installing Ubuntu(20.04) using Virtual Box.

1. Install the Oracle VirtualBox -> https://www.virtualbox.org/wiki/Downloads 

 2. Download the Ubuntu 20.04 ISO image. -> https://releases.ubuntu.com/focal/ 

complete the Ubuntu(20.04) installation on windows using this -> setup Ubuntu 20.04 on Windows 10/11

open a terminal and run sudo apt update && sudo apt upgrade -y and then sudo snap refresh to get everything updated to the latest versions.


step II :-

Download Qualcomm Package Managaer (for linux) :- https://qpm.qualcomm.com/#/main/tools/details/QPM3

After downloading the Qualcomm package manager.

you have to licence agreement otherwise you may login error   

linl for product licence : https://www.qualcomm.com/agreements/https://www.qualcomm.com/agreements/


 You have to run this command in your terminal. -> sudo dpkg –i Qualcomm package manager.

 It will install the Qualcomm package manager in your environment.

 From terminal, run below commands:

  1.  qpm-cli --login
  2.  qpm-cli --license-activate qualcomm_neural_processing_sdk 
  3.  qpm-cli --extract qualcomm_neural_processing_sdk (or) qpm-cli --extract<full path to .qik file>

                                                                   Or

 From QPM3 Desktop App:

  1.   Open QPM3 App on desktop 
  2.  Goto Tools page, then select Qualcomm® Neural Processing SDK
  3.  Select version and click "Extract".

After install Qualcomm neural processing sdk . You will get this path. /opt/qcom/aistack/qairt/2.21.0.240210

step III : setting  SNPE SDK environment setup :-

Python

The SDK requires python3.8. If python3.8 is not already installed on your system, you may install it with the following commands:

  • $ sudo apt-get update
  • $ sudo apt-get install python3.8 python3-distutils libpython3.8

To work with TensorFlow 1.15.0, Python 3.6 is required. Install Python 3.6 with the following commands:
  • $ sudo apt-get install software-properties-common
  • $ sudo add-apt-repository ppa:deadsnakes/ppa
  • $ sudo apt-get update
  • $ sudo apt-get install python3.6 python3-distutils libpython3.6
Virtual Environment (VENV)

to tackle conflict between different version of python you can use virtual enviroment

  • $ sudo apt-get install python3.8-venv
  • $ python3.8 -m venv "<PYTHON3.8_VENV_ROOT>"
  • $ source <PYTHON3.8_VENV_ROOT>/bin/activate
To work with TensorFlow 1.15.0, Python 3.6 is required:
  • $ sudo apt-get install python3.6-dev python3.6-venv
  • $ python3.6 -m venv "<PYTHON3.6_VENV_ROOT>"
  • $ source <PYTHON3.6_VENV_ROOT>/bin/activate
run the following command to check any missing dependencies :-
  • $ python3 -m pip install --upgrade pip
  • $ ${SNPE_ROOT}/bin/check-python-dependency
Clang 9

install clang 9 and linux dependencies with following command :-
  •  $ sudo bash ${SNPE_ROOT}/bin/check-linux-dependency.sh
Supported ML Frameworks Versions :-
  • TensorFlow: tf-1.15.0,or tf-2.10.1 
  • TFLite: tflite-2.3.0
  •  PyTorch: torch-1.13.1
  •  ONNX: onnx-1.11.0
  •  ONNX Runtime: onnxruntime-1.11.1

Make 

install make with following command :

  • $ sudo apt-get install make

Android NDK

install Android NDK version r25c with this link ->https://dl.google.com/android/repository/android-ndk-r25c-linux.zip

After download, extract the zip file and add the extracted location to your PATH environment variable.

Use the following commands to set the environment to use Android NDK and check configuration :

  • $ export ANDROID_NDK_ROOT=<PATH-TO-NDK>
  • $ export PATH=${ANDROID_NDK_ROOT}:${PATH}
  • $ ${SNPE_ROOT}/bin/envcheck -n
to check if enviroment is properly setup to use clang 9 run the following command :-
  •  ${SNPE_ROOT}/bin/envcheck -c

Java :-

Java environment is required to integrate Qualcomm® Neural Processing SDK with Android applications. Java 8 is required check if Java 8 is installed or not using following command :-
  • $ sudo apt-get install openjdk-8-jdk

Now to check if the linux enviroment is setup proper run the following command :

  • $ source ${SNPE_ROOT}/bin/envsetup.sh

This will set/update the following environment variables:
  •  SNPE_ROOT
  •  PYTHONPATH
  •  PATH 
  • LD_LIBRARY_PATH


Machine Learning frameworks 

ensure you have installed the required version of ML framework to use 

you check if your ml frameworks are in your pythonpath by following commands for respective ML frameworks :

  • python -c "import tensorflow"
  • python -c "import onnx"
  • python -c "import tflite"
  • python -c "import torch"

read out the next blog , where we will learn to execute Inception_V3  using SNPE SDK.












Comments

Popular posts from this blog

Examples of running Machine Learning Model on Device using Qualcomm AI HUB

Medical Report Analyzer - Progess

Running Inception_V3 using On-device AI