feat: Update NNSDK path and library linking in CMake configurations and Android build script, and add a new script to build all Android examples.
This commit is contained in:
parent
79a2bd27f6
commit
21105e3db7
35 changed files with 1438 additions and 1222 deletions
|
|
@ -1,118 +1,132 @@
|
|||
## Model Description
|
||||
|
||||
This model is converted from MobileNetV2 pretrained weights
|
||||
originally released by Google under the Apache License 2.0.
|
||||
|
||||
Original model:
|
||||
- Architecture: MobileNetV2
|
||||
- Source: TensorFlow / Keras official implementation
|
||||
|
||||
The model has been converted and optimized into ADLA format
|
||||
for deployment on Amlogic NPU platforms.
|
||||
|
||||
## Demo Run
|
||||
|
||||
### CPP
|
||||
|
||||
#### 1. Compile
|
||||
|
||||
**Prerequisites:**
|
||||
- Android NDK (r25e recommended)
|
||||
- `ANDROID_NDK_PATH` environment variable set
|
||||
|
||||
**Build:**
|
||||
```bash
|
||||
# Build for arm64-v8a
|
||||
cd examples/mobilenet/cpp
|
||||
./build-android.sh -a arm64-v8a
|
||||
```
|
||||
|
||||
The executable will be generated at `build/android/mobilenet_v2_demo` (Note: executable name may vary, verify in build folder).
|
||||
|
||||
#### 2. Run
|
||||
|
||||
```bash
|
||||
# Push executable to device
|
||||
adb push build/android/mobilenet_v2_demo /data/local/tmp/
|
||||
adb push model/mobilenet_v2_1.0_224_quant_A311D2.adla /data/local/tmp/
|
||||
adb push model/cat_224x224.jpg /data/local/tmp/
|
||||
adb push model/labels.txt /data/local/tmp/
|
||||
|
||||
# Run on device
|
||||
adb shell
|
||||
cd /data/local/tmp
|
||||
chmod +x mobilenet_v2_demo
|
||||
export LD_LIBRARY_PATH=/vendor/lib64 or (/vendor/lib)
|
||||
|
||||
# Usage: ./mobilenet_v2_demo <model_path> <image_path> <labels_path>
|
||||
./mobilenet_v2_demo mobilenet_v2_1.0_224_quant_A311D2.adla cat_224x224.jpg labels.txt
|
||||
```
|
||||
|
||||
**Note:** Replace `mobilenet_v2_1.0_224_quant_A311D2.adla` with your actual model file path.
|
||||
|
||||
### Python
|
||||
|
||||
**Prerequisites:**
|
||||
- Python 3.10
|
||||
- Required packages: `numpy`, `Pillow`, `amlnnlite`
|
||||
|
||||
**Install dependencies:**
|
||||
```bash
|
||||
pip install numpy Pillow amlnnlite-1.0.0-cp310-cp310-linux_aarch64.whl
|
||||
```
|
||||
|
||||
**Run on device:**
|
||||
```bash
|
||||
# Basic usage
|
||||
python mobilenetv2.py --model-path ./mobilenet_v2_1.0_224_quant_A311D2.adla
|
||||
|
||||
# Run with performance testing (100 cycles)
|
||||
python mobilenetv2.py --model-path ./mobilenet_v2_1.0_224_quant_A311D2.adla --run-cycles 100
|
||||
```
|
||||
|
||||
The script will automatically process all image files (`.jpg`, `.jpeg`, `.png`, `.bmp`) in the current directory and display top-5 classification results for each image.
|
||||
|
||||
## Results
|
||||
|
||||
The program will print the top-5 classification results with probabilities for each processed image.
|
||||
|
||||
**Example output:**
|
||||
```
|
||||
# python demo result
|
||||
============================================================
|
||||
Processing image 1/3: dog_224x224.jpg
|
||||
============================================================
|
||||
|
||||
Top-5 Classification Results:
|
||||
1. Shih-Tzu (probability: 0.9239)
|
||||
2. Pekinese (probability: 0.0476)
|
||||
3. Lhasa (probability: 0.0263)
|
||||
4. Brabancon griffon (probability: 0.0004)
|
||||
5. Dandie Dinmont (probability: 0.0003)
|
||||
|
||||
============================================================
|
||||
Processing image 2/3: cat_224x224.jpg
|
||||
============================================================
|
||||
|
||||
Top-5 Classification Results:
|
||||
1. tiger cat (probability: 0.4774)
|
||||
2. tabby (probability: 0.4324)
|
||||
3. Egyptian cat (probability: 0.0542)
|
||||
4. lynx (probability: 0.0150)
|
||||
5. Persian cat (probability: 0.0025)
|
||||
|
||||
============================================================
|
||||
Processing image 3/3: fish_224x224.jpeg
|
||||
============================================================
|
||||
|
||||
Top-5 Classification Results:
|
||||
1. goldfish (probability: 0.9998)
|
||||
2. conch (probability: 0.0001)
|
||||
3. trifle (probability: 0.0000)
|
||||
4. axolotl (probability: 0.0000)
|
||||
5. American lobster (probability: 0.0000)
|
||||
```
|
||||
|
||||
The classification results show the model's confidence scores (probabilities) for each detected class, with the highest probability indicating the most likely classification.
|
||||
|
||||
|
||||
## Model Description
|
||||
|
||||
This model is converted from MobileNetV2 pretrained weights
|
||||
originally released by Google under the Apache License 2.0.
|
||||
|
||||
Original model:
|
||||
- Architecture: MobileNetV2
|
||||
- Source: TensorFlow / Keras official implementation
|
||||
|
||||
The model has been converted and optimized into ADLA format
|
||||
for deployment on Amlogic NPU platforms.
|
||||
|
||||
## Demo Run
|
||||
|
||||
### CPP
|
||||
|
||||
#### 1. Compile
|
||||
|
||||
#### AMLNN SDK Setup
|
||||
|
||||
Resolve the AMLNN nnsdk dependency using one of the following methods:
|
||||
|
||||
- **Priority 1 – Environment variable (recommended)**
|
||||
```bash
|
||||
export AMLNN_HOME=/path/to/amlnn-toolkit
|
||||
```
|
||||
- **Priority 3 – Sibling directory fallback** *(automatic)*
|
||||
Place `amlnn-toolkit` as a sibling to `amlnn-model-playground`:
|
||||
```bash
|
||||
git clone git@github.com:Amlogic-NN/amlnn-toolkit.git ../amlnn-toolkit
|
||||
```
|
||||
|
||||
**Prerequisites:**
|
||||
- Android NDK (r25e recommended)
|
||||
- `ANDROID_NDK_PATH` environment variable set
|
||||
|
||||
**Build:**
|
||||
```bash
|
||||
# Build for arm64-v8a
|
||||
cd examples/mobilenet/cpp
|
||||
./build-android.sh -a arm64-v8a
|
||||
```
|
||||
|
||||
The executable will be generated at `build/android/mobilenet_v2_demo` (Note: executable name may vary, verify in build folder).
|
||||
|
||||
#### 2. Run
|
||||
|
||||
```bash
|
||||
# Push executable to device
|
||||
adb push build/android/mobilenet_v2_demo /data/local/tmp/
|
||||
adb push model/mobilenet_v2_1.0_224_quant_A311D2.adla /data/local/tmp/
|
||||
adb push model/cat_224x224.jpg /data/local/tmp/
|
||||
adb push model/labels.txt /data/local/tmp/
|
||||
|
||||
# Run on device
|
||||
adb shell
|
||||
cd /data/local/tmp
|
||||
chmod +x mobilenet_v2_demo
|
||||
export LD_LIBRARY_PATH=/vendor/lib64 or (/vendor/lib)
|
||||
|
||||
# Usage: ./mobilenet_v2_demo <model_path> <image_path> <labels_path>
|
||||
./mobilenet_v2_demo mobilenet_v2_1.0_224_quant_A311D2.adla cat_224x224.jpg labels.txt
|
||||
```
|
||||
|
||||
**Note:** Replace `mobilenet_v2_1.0_224_quant_A311D2.adla` with your actual model file path.
|
||||
|
||||
### Python
|
||||
|
||||
**Prerequisites:**
|
||||
- Python 3.10
|
||||
- Required packages: `numpy`, `Pillow`, `amlnnlite`
|
||||
|
||||
**Install dependencies:**
|
||||
```bash
|
||||
pip install numpy Pillow amlnnlite-1.0.0-cp310-cp310-linux_aarch64.whl
|
||||
```
|
||||
|
||||
**Run on device:**
|
||||
```bash
|
||||
# Basic usage
|
||||
python mobilenetv2.py --model-path ./mobilenet_v2_1.0_224_quant_A311D2.adla
|
||||
|
||||
# Run with performance testing (100 cycles)
|
||||
python mobilenetv2.py --model-path ./mobilenet_v2_1.0_224_quant_A311D2.adla --run-cycles 100
|
||||
```
|
||||
|
||||
The script will automatically process all image files (`.jpg`, `.jpeg`, `.png`, `.bmp`) in the current directory and display top-5 classification results for each image.
|
||||
|
||||
## Results
|
||||
|
||||
The program will print the top-5 classification results with probabilities for each processed image.
|
||||
|
||||
**Example output:**
|
||||
```
|
||||
# python demo result
|
||||
============================================================
|
||||
Processing image 1/3: dog_224x224.jpg
|
||||
============================================================
|
||||
|
||||
Top-5 Classification Results:
|
||||
1. Shih-Tzu (probability: 0.9239)
|
||||
2. Pekinese (probability: 0.0476)
|
||||
3. Lhasa (probability: 0.0263)
|
||||
4. Brabancon griffon (probability: 0.0004)
|
||||
5. Dandie Dinmont (probability: 0.0003)
|
||||
|
||||
============================================================
|
||||
Processing image 2/3: cat_224x224.jpg
|
||||
============================================================
|
||||
|
||||
Top-5 Classification Results:
|
||||
1. tiger cat (probability: 0.4774)
|
||||
2. tabby (probability: 0.4324)
|
||||
3. Egyptian cat (probability: 0.0542)
|
||||
4. lynx (probability: 0.0150)
|
||||
5. Persian cat (probability: 0.0025)
|
||||
|
||||
============================================================
|
||||
Processing image 3/3: fish_224x224.jpeg
|
||||
============================================================
|
||||
|
||||
Top-5 Classification Results:
|
||||
1. goldfish (probability: 0.9998)
|
||||
2. conch (probability: 0.0001)
|
||||
3. trifle (probability: 0.0000)
|
||||
4. axolotl (probability: 0.0000)
|
||||
5. American lobster (probability: 0.0000)
|
||||
```
|
||||
|
||||
The classification results show the model's confidence scores (probabilities) for each detected class, with the highest probability indicating the most likely classification.
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,8 @@ echo "BUILD_DIR: ${BUILD_DIR}"
|
|||
mkdir -p ${BUILD_DIR}
|
||||
cd ${BUILD_DIR}
|
||||
|
||||
cmake ../../src \
|
||||
cmake -Wno-dev ../../src \
|
||||
-DAMLNN_HOME=${AMLNN_HOME:-} \
|
||||
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_PATH}/build/cmake/android.toolchain.cmake \
|
||||
-DANDROID_ABI=${TARGET_ABI} \
|
||||
-DANDROID_PLATFORM=android-24 \
|
||||
|
|
|
|||
|
|
@ -1,31 +1,21 @@
|
|||
cmake_minimum_required(VERSION 3.5)
|
||||
cmake_minimum_required(VERSION 3.10...3.27)
|
||||
project(mobilenet_v2_demo)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
# Set NNSDK path
|
||||
if(NOT DEFINED NNSDK_DIR)
|
||||
set(NNSDK_DIR "${CMAKE_SOURCE_DIR}/../../../../../amlnn-toolkit/nn_runtime/nnsdk")
|
||||
endif()
|
||||
set(NNSDK_ROOT "${NNSDK_DIR}")
|
||||
message(STATUS "NNSDK_ROOT: ${NNSDK_ROOT}")
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../../../../cmake")
|
||||
find_package(AMLNN REQUIRED)
|
||||
include_directories(${AMLNN_INCLUDE_DIR})
|
||||
link_directories(${AMLNN_LIBRARY_DIR})
|
||||
|
||||
include_directories(${NNSDK_ROOT}/include)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/../../../../common)
|
||||
|
||||
# Set dependency path
|
||||
set(3RDPARTY_DIR "${CMAKE_SOURCE_DIR}/../../../../dependency")
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Android")
|
||||
if (ANDROID_ABI STREQUAL "arm64-v8a")
|
||||
link_directories(${NNSDK_ROOT}/android/arm64-v8a)
|
||||
else()
|
||||
link_directories(${NNSDK_ROOT}/android/armeabi-v7a)
|
||||
endif()
|
||||
# Android needs log
|
||||
link_libraries(log)
|
||||
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
link_directories(${NNSDK_ROOT}/linux/yocto/aarch64-poky-linux)
|
||||
endif()
|
||||
|
||||
# Find OpenCV
|
||||
|
|
@ -40,5 +30,5 @@ add_executable(mobilenet_v2_demo
|
|||
|
||||
target_link_libraries(mobilenet_v2_demo
|
||||
${OpenCV_LIBS}
|
||||
nnsdk
|
||||
${AMLNN_LIBRARY}
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue