4. 安装最新的Android NDK,可以从Android Studio SDK Manager中安装,或者独立安装。
5. 安装Caffe(安装说明,本SDK推荐的git修订版d8f79537)。
# this will build Caffe (and the pycaffe bindings) from source - see the official instructions for more information
sudo apt-get install cmake git libatlas-base-dev libboost-all-dev libgflags-dev libgoogle-glog-dev libhdf5-serial-dev libleveldb-dev liblmdb-dev libopencv-dev libprotobuf-dev libsnappy-dev protobuf-compiler python-dev python-numpy
git clone https://github.com/BVLC/caffe.git ~/caffe; cd ~/caffe; git reset --hard d8f79537
mkdir build; cd build; cmake ..; make all -j4; make install 6. 可选:安装TensorFlow(推荐安装说明,版本1.0)。
# this will download and install TensorFlow in a virtual environment - see the official instructions for more information
sudo apt-get install python-pip python-dev python-virtualenv
mkdir ~/tensorflow; virtualenv --system-site-packages ~/tensorflow; source ~/tensorflow/bin/activate
pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.0.0-cp27-none-linux_x86_64.whl 设置SDK
# install a few more SDK dependencies, then perform a comprehensive check
sudo apt-get install python-dev python-matplotlib python-numpy python-protobuf python-scipy python-skimage python-sphinx wget zip
source ~/snpe-sdk/bin/dependencies.sh # verifies that all dependencies are installed
source ~/snpe-sdk/bin/check_python_depends.sh # verifies that the python dependencies are installed 5. 在当前控制台上初始化Snapdragon NPE SDK环境; 在将来,为每个新的控制台重复此操作:
# initialize the environment on the current console
cd ~/snpe-sdk/
export ANDROID_NDK_ROOT=~/Android/Sdk/ndk-bundle # default location for Android Studio, replace with yours
source ./bin/envsetup.sh -c ~/caffe
source ./bin/envsetup.sh -t ~/tensorflow # optional for this guide 初始化将设置或更新$$SNPE_ROOT,$PATH,$LD_LIBRARY_PATH,$PYTHONPATH,$CAFFE_HOME,$TENSORFLOW_HOME,此外,它将在本地复制Android NDK libgnustl_shared.so库,并更新Android AAR存档。
cd $SNPE_ROOT
python ./models/alexnet/scripts/setup_alexnet.py -a ./temp-assets-cache -d 提示:查看setup_alexnet.py脚本,该脚本执行到DLC的转换。 您可能会对您的Caffe模型转换执行相同的操作。
可选:以Tensorflow格式下载并转换预训练的“inception_v3”示例:
cd $SNPE_ROOT
python ./models/inception_v3/scripts/setup_inceptionv3.py -a ./temp-assets-cache -d 提示:看一下setup_inceptionv3.py脚本,它也对模型进行了量化,缩小了75%(91MB→23MB)。
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.选项A:从Android studio构建Android APK: