Running Inception_V3 using On-device AI
Introduction
The Inception v3 Imagenet classification model is trained to classify images with 1000 labels.
Inception-V3 is a convolutional neural network architecture designed for image classification and recognition tasks.
Tensorflow Setup :
To set up TensorFlow, perform the following procedure:
1. Download android-ndk-
$export ANDROID_NDK_ROOT=<path to Android Ndk root>
2. Go to the SNPE SDK root directory, and run the following script to set up the SNPE SDK environment (the TensorFlow home directory must be provided):
- $export TENSORFLOW_DIR=/usr2/
/.local/bin/ $source bin/envsetup.sh -t $TENSORFLOW_DIR
SNPE_ROOT: root directory of the SNPE SDK installation TENSORFLOW_HOME: root directory of the TensorFlow installation provided
PATH, LD_LIBRARY_PATH, and PYTHONPATH.
Running Inception_V3 Model
Convert the TensorFlow Inception_v3 model to DLC
1. Download the Inception_v3 model and assets from https://storage.googleapis.com/download.tensorflow.org/models/inception_v3_2016_ 08_28_frozen.pb.tar.gz into the tmp folder.
- $cd $SNPE_ROOT $mkdir tmp $wget -N ./tmp “https://storage.googleapis.com/download.tensorflow.org/models/inception _v3_2016_08_28_frozen.pb.tar.gz”
2. Prepare input data for the Inception_v3 model.
- The SNPE requires that the input image be in a format that is different from Caffe or TensorFlow networks.
- In the SNPE, the image must be presented as a tensor of shape (height × width × channel), where channel is the fastest-changing dimension.
3. Create the folder structure like this in the examples/Models/inception_V3 folder
- $cd $SNPE_ROOT/models/inception_v3/ $mkdir -p tensorflow_dlc_data/cropped $tar -xzf ./tmp/inception_v3_2016_08_28_frozen.pb.tar.gz -C models/inception_v3/tensorflow
- $cp tensorflow/imagenet_slim_labels.txt data/
- $cp $SNPE_ROOT/models/alexnet/data/*.jpg data/
- $python $SNPE_ROOT
- /models/inception_v3/scripts/create_inceptionv3_raws.py -i data -d
- data/cropped/ -s 299
- $python $SNPE_ROOT /models/inception_v3/scripts/create_file_list.py -i
- data/cropped -o data/cropped/raw_list.txt -e *.raw
- $python $SNPE_ROOT/ /models/inception_v3/scripts/ create_file_list.py -i
- data/cropped -o data/target_raw_list.txt -e *.raw -r
- $snpe-tensorflow-to-dlc --graph tensorflow/inception_v3_2016_08_28_frozen.pb --input_dim input "1,299,299,3" --out_node InceptionV3/Predictions/Reshape_1 --dlc inception_v3.dlc
- $cd $SNPE_ROOT/models/inception_v3 $snpe-net-run --container dlc/inception_v3_quantized.dlc --input_list data/cropped/raw_list.txt
- $python $SNPE_ROOT/models/inception_v3/scripts/show_inceptionv3_classifications.py -i data/cropped/raw_list.txt \ -o output/ \ -l data/imagenet_slim_labels.txt
- $export SNPE_TARGET_ARCH= aarch64-android-clang5.0
- $export SNPE_TARGET_STL=libgnustl_shared.so $adb shell "mkdir -p /data/local/tmp/snpeexample/$SNPE_TARGET_ARCH/bin"
- $adb shell "mkdir -p /data/local/tmp/snpeexample/
- $SNPE_TARGET_ARCH/lib"
- $adb shell "mkdir -p /data/local/tmp/snpeexample/dsp/lib"
- $adb push
- $SNPE_ROOT/lib/
- $SNPE_TARGET_ARCH/* /data/local/tmp/snpeexample/
- $SNPE_TARGET_ARCH/lib $adb push $SNPE_ROOT/lib/dsp/* \ \ /data/local/tmp/snpeexample/dsp/lib $adb push
- $SNPE_ROOT/bin/$SNPE_TARGET_ARCH/snpe-net-run \ /data/local/tmp/snpeexample/$SNPE_TARGET_ARCH/bin
- $cd $SNPE_ROOT/models/inception_v3
- $mkdir data/rawfiles && cp data/cropped/*.raw data/rawfiles/
- $adb shell "mkdir -p /data/local/tmp/inception_v3"
- $adb push data/rawfiles /data/local/tmp/inception_v3/cropped
- $adb push data/target_raw_list.txt /data/local/tmp/inception_v3
- $adb push dlc/inception_v3_quantized.dlc /data/local/tmp/inception_v3 $rm -rf data/rawfiles
- $adb pull /data/local/tmp/inception_v3/output output_android
- $python scripts/show_inceptionv3_classifications.py \ -i data/target_raw_list.txt \ -o output_android \ -l data/imagenet_slim_labels.txt
- your_model.dlc
- A text file listing all the input data. For an example, see: $SNPE_ROOT/models/alexnet/data/image_list.txt.
- All the input data listed in the text file. For an example, see $SNPE_ROOT/models/alexnet/data/cropped.
- $cd $SNPE_ROOT/benchmarks
- $python snpe_bench.py -c inception_v3.json
- cd $SNPE_ROOT/benchmarks/inception_v3/results
- cd $SNPE_ROOT/benchmarks/inception_v3/results/latest_results

Comments
Post a Comment