WasmEdge CLI tools for Android
First, install WasmEdge-TensorFlow-Tools pre-release on your Android device. It works with the Android version of TensorFlow-Lite dynamic shared library.
Android developer options
Currently, WasmEdge only supports the arm64-v8a architecture on Android devices. You need an arm64-v8a Android simulator or a physical device with . WasmEdge requires Android 6.0 and above.
In Ubuntu Linux, you can use the command to install Android debugging and testing tool adb
. Using the adb shell
command on the Ubuntu dev machine, you can open a CLI shell to execute commands on the connected Android device.
$ wget https://github.com/second-state/WasmEdge-tensorflow-tools/releases/download/0.10.0/WasmEdge-tensorflow-tools-0.10.0-android_aarch64.tar.gz
$ mkdir WasmEdge-tensorflow-tools && tar zxvf WasmEdge-tensorflow-tools-0.10.0-android_aarch64.tar.gz -C WasmEdge-tensorflow-tools
show-tflite-tensor
We provide an Android compatible version of TensorFlow-Lite dynamic shared library in the WasmEdge-Tensorflow-deps package. Download the package to your Ubuntu dev machine as follows.
$ wget https://github.com/second-state/WasmEdge-tensorflow-deps/releases/download/0.10.0/WasmEdge-tensorflow-deps-TFLite-0.10.0-android_aarch64.tar.gz
$ tar zxvf WasmEdge-tensorflow-deps-TFLite-0.10.0-android_aarch64.tar.gz -C WasmEdge-tensorflow-tools
libtensorflowlite_c.so
Next use the adb
tool to push the downloaded WasmEdge-TensorFlow packages onto a connected Android device.
In this example, we will demonstrate a standard WasmEdge Tensorflow-Lite sample application. It can recognize and classify the bird type from a JPG or PNG picture of a bird. The explanation of the source code can be .
git clone https://github.com/second-state/wasm-learning.git
cd wasm-learning/rust/birds_v1
rustup target add wasm32-wasi
cargo build --release --target=wasm32-wasi
Push the Wasm bytecode file, tensorflow lite model file, and the test bird picture file onto the Android device using adb
.
Type adb shell
from the Ubuntu CLI to open a command shell for the connected Android device. Confirm that the tools, programs, and test image are all available on the Android device under the /data/local/tmp/WasmEdge-tensorflow-tools
folder.
$ adb shell
sirius:/ $ cd /data/local/tmp/WasmEdge-tensorflow-tools
sirius:/data/local/tmp/WasmEdge-tensorflow-tools $ ls
bird.jpg lite-model_aiy_vision_classifier_birds_V1_3.tflite
birds_v1.wasm show-tflite-tensor
Load the TensorFlow-Lite dynamic shared library, and use the show-tflite-tensor
CLI tool to examine the Tensorflow Lite model file.
sirius:/data/local/tmp/WasmEdge-tensorflow-tools $ export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH
sirius:/data/local/tmp/WasmEdge-tensorflow-tools $ ./show-tflite-tensor lite-model_aiy_vision_classifier_birds_V1_3.tflite
INFO: Initialized TensorFlow Lite runtime.
Input tensor nums: 1
Input tensor name: module/hub_input/images_uint8
dimensions: [1 , 224 , 224 , 3]
data type: UInt8
tensor byte size: 150528
Output tensor nums: 1
Output tensor name: module/prediction
dimensions: [1 , 965]
tensor byte size: 965
The result shows that the bird type is in line 166 of the label file (Sicalis flaveola) and the confidence level is 84.7%.