docs: Update README and compilation guides for clarity and consistency, including path corrections and improved formatting. Add copyright notices to source files and adjust file permissions for several scripts and directories.

This commit is contained in:
dian.yuan 2026-02-28 11:06:26 +08:00
parent f960c5030d
commit bd891a96dd
136 changed files with 14413 additions and 9399 deletions

View file

@ -1,133 +1,133 @@
# yolov8
## 1.Overview
YOLOv8 was released by Ultralytics on January 10, 2023, offering cutting-edge performance in terms of accuracy and speed. Building upon the advancements of previous YOLO versions, YOLOv8 introduced new features and optimizations that make it an ideal choice for various [object detection](https://www.ultralytics.com/blog/a-guide-to-deep-dive-into-object-detection-in-2025) tasks in a wide range of applications.
## 2.Model Download
- **Open Source model**
- **Open Source projects:** https://github.com/ultralytics/ultralytics/tree/v8.2.0
- **Export Model Step:**
- **Install ultralytics**
pip install torch==2.4.1
pip install torchvision==0.19.1
pip install ultralytics==8.2.0
- **Download weights**
wget https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8m.pt
wget https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8s.pt
wget https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8n.pt
- **Export Model**
```
from ultralytics import YOLO
model = YOLO("yolov8m.pt")
model.export(format="onnx", opset=12, simplify=True, dynamic=False, imgsz=640)
```
- **Exported Model**
link to amlogic server( **onnx model or quantized tflite**)
## 3. Model Conversion
```
cd model
Usage: ./adla_covnert.sh model_path adla_tookkit_path target_platform
example
./adla_covnert.sh yolov8m.onnx /xxxx/adla-toolkit-binary-3.2.9.3 PRODUCT_PID0XA005
./adla_covnert.sh yolov8s.onnx /xxxx/adla-toolkit-binary-3.2.9.3 PRODUCT_PID0XA005
./adla_covnert.sh yolov8n.onnx /xxxx/adla-toolkit-binary-3.2.9.3 PRODUCT_PID0XA005
```
| Parameter | Discription |
| ----------------- | ------------------------------------------------------------ |
| model_path | onnx model path |
| adla_tookkit_path | path to adla_toolkit |
| target_platform | Specify target platform. for A311D2 : PRODUCT_PID0XA003. for S905X5: PRODUCT_PID0XA005 |
## 4. Demo Run
### CPP
#### 1. Compile
**Prerequisites:**
- Android NDK (r25e recommended)
- `ANDROID_NDK_PATH` environment variable set
**Build:**
```bash
# Build for arm64-v8a
cd examples/yolov8/cpp
AMLNN_HOME=/path/to/amlnn-toolkit ./build-android.sh -a arm64-v8a
```
The executable will be generated at `build/android/yolov8_demo` (Note: executable name may vary, verify in build folder).
#### 2. Run
```bash
# Push executable to device
adb push build/android/yolov8_demo /data/local/tmp/
adb push model/yolov8s_int8_A311D2.adla /data/local/tmp/
adb push test_image.jpg /data/local/tmp/
# Run on device
adb shell
cd /data/local/tmp
chmod +x yolov8_demo
export LD_LIBRARY_PATH=/vendor/lib64 or (/vendor/lib)
# Usage: ./yolo_world_demo <model_path> <image_path>
./yolov8_demo yolov8s_int8_A311D2.adla test_image.jpg"
```
**Note:** Replace `yolov8s_int8_A311D2.adla` with your actual model file path.
### Python
**Prerequisites:**
- Python 3.10
- Required packages: `numpy`, `opencv-python`, `amlnnlite`
**Install dependencies:**
```bash
pip install numpy opencv-python amlnnlite-1.0.0-cp310-cp310-linux_aarch64.whl
```
**Run on device:**
```bash
python yolov8.py --model-path ./yolov8s_int8_A311D2.adla
```
The script will automatically process all image files (`.jpg`, `.jpeg`, `.png`, `.bmp`) in the current directory and save results to a `{model_name}_result` folder.
## 5.Results
The program will print the detection count and inference time. The result image with bounding boxes will be saved to the specified output path (`result.jpg` by default).
You can pull the result image back to view it:
```bash
adb pull result.jpg.
```
![alt text](result.jpg)
# yolov8
## 1.Overview
YOLOv8 was released by Ultralytics on January 10, 2023, offering cutting-edge performance in terms of accuracy and speed. Building upon the advancements of previous YOLO versions, YOLOv8 introduced new features and optimizations that make it an ideal choice for various [object detection](https://www.ultralytics.com/blog/a-guide-to-deep-dive-into-object-detection-in-2025) tasks in a wide range of applications.
## 2.Model Download
- **Open Source model**
- **Open Source projects:** https://github.com/ultralytics/ultralytics/tree/v8.2.0
- **Export Model Step:**
- **Install ultralytics**
pip install torch==2.4.1
pip install torchvision==0.19.1
pip install ultralytics==8.2.0
- **Download weights**
wget https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8m.pt
wget https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8s.pt
wget https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8n.pt
- **Export Model**
```
from ultralytics import YOLO
model = YOLO("yolov8m.pt")
model.export(format="onnx", opset=12, simplify=True, dynamic=False, imgsz=640)
```
- **Exported Model**
link to amlogic server( **onnx model or quantized tflite**)
## 3. Model Conversion
```
cd model
Usage: ./adla_convert.sh model_path adla_toolkit_path target_platform
example
./adla_convert.sh yolov8m.onnx /xxxx/adla-toolkit-binary-3.2.9.3 PRODUCT_PID0XA005
./adla_convert.sh yolov8s.onnx /xxxx/adla-toolkit-binary-3.2.9.3 PRODUCT_PID0XA005
./adla_convert.sh yolov8n.onnx /xxxx/adla-toolkit-binary-3.2.9.3 PRODUCT_PID0XA005
```
| Parameter | Description |
| ----------------- | ------------------------------------------------------------ |
| model_path | onnx model path |
| adla_toolkit_path | path to adla_toolkit |
| target_platform | Specify target platform. for A311D2 : PRODUCT_PID0XA003。for S905X5: PRODUCT_PID0XA005 |
## 4. Demo Run
### CPP
#### 1. Compile
**Prerequisites:**
- Android NDK (r25e recommended)
- `ANDROID_NDK_PATH` environment variable set
**Build:**
```bash
# Build for arm64-v8a
cd examples/yolov8/cpp
./build-android.sh -a arm64-v8a
```
The executable will be generated at `build/android/yolov8_demo` (Note: executable name may vary, verify in build folder).
#### 2. Run
```bash
# Push executable to device
adb push build/android/yolov8_demo /data/local/tmp/
adb push model/yolov8s_int8_A311D2.adla /data/local/tmp/
adb push test_image.jpg /data/local/tmp/
# Run on device
adb shell
cd /data/local/tmp
chmod +x yolov8_demo
export LD_LIBRARY_PATH=/vendor/lib64 or (/vendor/lib)
# Usage: ./yolo_world_demo <model_path> <image_path>
./yolov8_demo yolov8s_int8_A311D2.adla test_image.jpg"
```
**Note:** Replace `yolov8s_int8_A311D2.adla` with your actual model file path.
### Python
**Prerequisites:**
- Python 3.10
- Required packages: `numpy`, `opencv-python`, `amlnnlite`
**Install dependencies:**
```bash
pip install numpy opencv-python amlnnlite-1.0.0-cp310-cp310-linux_aarch64.whl
```
**Run on device:**
```bash
python yolov8.py --model-path ./yolov8s_int8_A311D2.adla
```
The script will automatically process all image files (`.jpg`, `.jpeg`, `.png`, `.bmp`) in the current directory and save results to a `{model_name}_result` folder.
## 5.Results
The program will print the detection count and inference time. The result image with bounding boxes will be saved to the specified output path (`result.jpg` by default).
You can pull the result image back to view it:
```bash
adb pull result.jpg.
```
![alt text](result.jpg)

View file

@ -1,36 +1,36 @@
cmake_minimum_required(VERSION 3.10...3.27)
project(yolo_world_demo)
set(CMAKE_CXX_STANDARD 17)
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(${CMAKE_SOURCE_DIR}/../../../../common)
# Set 3rdparty path
set(3RDPARTY_DIR "${CMAKE_SOURCE_DIR}/../../../../dependency")
if(CMAKE_SYSTEM_NAME STREQUAL "Android")
# Android needs log
link_libraries(log)
endif()
# Find OpenCV
message(STATUS "OpenCV_DIR: ${OpenCV_DIR}")
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(yolov8_demo
main.cpp
postprocess.cpp
postprocess.h
${CMAKE_SOURCE_DIR}/../../../../common/model_loader.cpp
)
target_link_libraries(yolov8_demo
${OpenCV_LIBS}
${AMLNN_LIBRARY}
)
cmake_minimum_required(VERSION 3.10...3.27)
project(yolo_world_demo)
set(CMAKE_CXX_STANDARD 17)
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(${CMAKE_SOURCE_DIR}/../../../../common)
# Set 3rdparty path
set(3RDPARTY_DIR "${CMAKE_SOURCE_DIR}/../../../../dependency")
if(CMAKE_SYSTEM_NAME STREQUAL "Android")
# Android needs log
link_libraries(log)
endif()
# Find OpenCV
message(STATUS "OpenCV_DIR: ${OpenCV_DIR}")
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(yolov8_demo
main.cpp
postprocess.cpp
postprocess.h
${CMAKE_SOURCE_DIR}/../../../../common/model_loader.cpp
)
target_link_libraries(yolov8_demo
${OpenCV_LIBS}
${AMLNN_LIBRARY}
)

View file

@ -100,7 +100,7 @@ int main(int argc, char** argv) {
float* outbuf2 = (float*)outdata->out[2].buf;
const int channels = 144; // 64 DFL + 80 classes
std::vector<Detection> detections = postprocess(
std::make_tuple(outbuf0, std::make_tuple(MODEL_INPUT_HEIGHT / 8, MODEL_INPUT_WIDTH / 8, channels), 8),
std::make_tuple(outbuf1, std::make_tuple(MODEL_INPUT_HEIGHT / 16, MODEL_INPUT_WIDTH / 16, channels), 16),

View file

@ -59,7 +59,7 @@ static float compute_iou(const Detection& det1, const Detection& det2) {
float area1 = (det1.x2 - det1.x1) * (det1.y2 - det1.y1);
float area2 = (det2.x2 - det2.x1) * (det2.y2 - det2.y1);
return inter / (area1 + area2 - inter);
}
@ -96,7 +96,7 @@ static std::vector<Detection> nms_by_class(const std::vector<Detection>& detecti
std::tuple<cv::Mat, float, std::tuple<int, int>> preprocess(cv::Mat img, std::tuple<int, int> new_shape) {
cv::Mat img_rgb;
if (img.empty()) {
LOGE("Preprocess received empty image");
return {};
@ -128,7 +128,7 @@ std::tuple<cv::Mat, float, std::tuple<int, int>> preprocess(cv::Mat img, std::tu
int pad_bottom = static_cast<int>(round(pad_h / 2.0 + 0.1));
cv::Mat img_padded;
cv::copyMakeBorder(img_resized, img_padded, pad_top, pad_bottom, pad_left, pad_right,
cv::copyMakeBorder(img_resized, img_padded, pad_top, pad_bottom, pad_left, pad_right,
cv::BORDER_CONSTANT, cv::Scalar(114, 114, 114));
cv::Mat img_float;
@ -155,14 +155,14 @@ cv::Mat quantize_input(const cv::Mat& float_img, float scale, int8_t zero_point)
return quantized_img;
}
static std::vector<Detection> get_detections(float* output, std::tuple<int, int, int> output_shape,
static std::vector<Detection> get_detections(float* output, std::tuple<int, int, int> output_shape,
int stride, float conf_thresh) {
std::vector<Detection> detections;
int grid_h = std::get<0>(output_shape);
int grid_w = std::get<1>(output_shape);
int channels = std::get<2>(output_shape);
const int num_classes = 80;
const int dfl_channels = 64; // 4 directions * 16 bins
@ -288,9 +288,9 @@ cv::Mat draw_detections(cv::Mat image, const std::vector<Detection>& detections)
cv::Scalar color(rgb.at<cv::Vec3b>(0, 0)[0], rgb.at<cv::Vec3b>(0, 0)[1], rgb.at<cv::Vec3b>(0, 0)[2]);
// Draw bounding box
cv::rectangle(drawn_image,
cv::rectangle(drawn_image,
cv::Point(static_cast<int>(det.x1), static_cast<int>(det.y1)),
cv::Point(static_cast<int>(det.x2), static_cast<int>(det.y2)),
cv::Point(static_cast<int>(det.x2), static_cast<int>(det.y2)),
color, 2);
// Draw label
@ -304,17 +304,17 @@ cv::Mat draw_detections(cv::Mat image, const std::vector<Detection>& detections)
label_y = static_cast<int>(det.y1) + text_size.height + 5;
// Draw label background
cv::rectangle(drawn_image,
cv::rectangle(drawn_image,
cv::Point(label_x, label_y - text_size.height - baseline),
cv::Point(label_x + text_size.width, label_y + baseline),
cv::Point(label_x + text_size.width, label_y + baseline),
color, cv::FILLED);
// Determine text color based on background brightness
int brightness = (color[0] + color[1] + color[2]) / 3;
cv::Scalar text_color = brightness < 128 ? cv::Scalar(255, 255, 255) : cv::Scalar(0, 0, 0);
cv::putText(drawn_image, label,
cv::Point(label_x, label_y),
cv::putText(drawn_image, label,
cv::Point(label_x, label_y),
cv::FONT_HERSHEY_SIMPLEX, 0.6, text_color, 1, cv::LINE_AA);
}
return drawn_image;

0
examples/yolov8/model/.gitkeep Normal file → Executable file
View file

View file

@ -1,8 +1,24 @@
#
# Copyright (C) 2026 Amlogic, Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# 1. $1: set ADLA_TOOL_PATH
# 2. $2: set target-plaftorm
# 2. $2: set target-platform
# for A311D2 target-platform is PRODUCT_PID0XA003
# for S905X5 target-platform is PRODUCT_PID0XA005
# Usage: ./adla_covnert.sh yolov8m.onnx /XXX/adla-toolkit-binary-3.2.9.3 PRODUCT_PID0XA005
# Usage: ./adla_convert.sh yolov8m.onnx /XXX/adla-toolkit-binary-3.2.9.3 PRODUCT_PID0XA005
model_path=$1
ADLA_TOOL_PATH=$2
@ -10,7 +26,7 @@ target_platform=$3
echo "model_path:[$model_path]"
echo "ADLA_TOOL_PATH:[$ADLA_TOOL_PATH]"
echo "target-plaftorm:[$target_platform]"
echo "target-platform:[$target_platform]"
adla_convert=${ADLA_TOOL_PATH}/bin/adla_convert

0
examples/yolov8/py/.gitkeep Normal file → Executable file
View file

View file

@ -1,3 +1,19 @@
#
# Copyright (C) 2026 Amlogic, Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import numpy as np
import os
import glob
@ -206,7 +222,7 @@ def main():
# Initialize AMLNNLite
amlnn = AMLNNLite()
amlnn.config(
model_path=args.model_path, # Model file path, Support ADLD and quantized TFlite models
model_path=args.model_path, # Model file path, Support ADLA and quantized TFlite models
run_cycles=args.run_cycles
)
amlnn.init()