Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 93 additions & 9 deletions .github/workflows/cpp-model-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ on:
pull_request:
paths:
- 'src/cpp/**'
- 'src/rv182x_rk3588_yolo26/video/test.mp4'
- 'src/rk3576_yolov8_pose/video/test.mp4'
- '.github/workflows/cpp-model-images.yml'
push:
branches: [main]
paths:
- 'src/cpp/**'
- 'src/rv182x_rk3588_yolo26/video/test.mp4'
- 'src/rk3576_yolov8_pose/video/test.mp4'
- '.github/workflows/cpp-model-images.yml'
workflow_dispatch:
inputs:
Expand All @@ -24,20 +28,25 @@ concurrency:
group: cpp-model-images-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

env:
RUNTIME_IMAGE: rockchip-cv-runtime:${{ github.sha }}
PUBLISH: ${{ github.ref == 'refs/heads/main' && github.event_name != 'pull_request' }}
MODEL_ID: ${{ inputs.model }}
CHECK_N_INT8: ${{ github.event_name == 'pull_request' }}

jobs:
images:
runtime:
runs-on: ubuntu-24.04-arm
timeout-minutes: 120
outputs:
families: ${{ steps.catalog.outputs.families }}
namespace: ${{ steps.catalog.outputs.namespace }}
permissions:
contents: read
packages: write
defaults:
run:
working-directory: src/cpp
env:
RUNTIME_IMAGE: rockchip-cv-runtime:${{ github.sha }}
PUBLISH: ${{ github.ref == 'refs/heads/main' && github.event_name != 'pull_request' }}
MODEL_ID: ${{ inputs.model }}
steps:
- uses: actions/checkout@v6
with:
Expand All @@ -47,10 +56,18 @@ jobs:
- uses: actions/setup-python@v6
with:
python-version: '3.12'
- name: Validate model catalog
- name: Validate model catalog and select families
id: catalog
shell: bash
run: |
python -m pip install 'PyYAML==6.0.3'
python tools/models.py validate
args=()
if [[ -n "$MODEL_ID" ]]; then args+=(--model "$MODEL_ID"); fi
families=$(python tools/models.py matrix "${args[@]}" | jq -c --arg check "$CHECK_N_INT8" '
.include | map(select($check != "true" or (.size == "n" and .precision == "int8")))
| {family: (map(.family) | unique)}')
echo "families=$families" >> "$GITHUB_OUTPUT"
echo "namespace=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT"
- uses: docker/login-action@v4
if: env.PUBLISH == 'true'
with:
Expand All @@ -62,7 +79,6 @@ jobs:
run: |
namespace="ghcr.io/${GITHUB_REPOSITORY,,}"
remote_runtime="$namespace/runtime:$GITHUB_SHA"
echo "IMAGE_NAMESPACE=$namespace" >> "$GITHUB_ENV"
if [[ "$PUBLISH" == true ]]; then
if output=$(docker pull --platform linux/arm64 "$remote_runtime" 2>&1); then
echo "$output"
Expand All @@ -82,11 +98,79 @@ jobs:
docker image tag "$RUNTIME_IMAGE" "$remote_runtime"
docker push "$remote_runtime"
fi
- name: Export runtime for verification jobs
if: env.PUBLISH != 'true'
shell: bash
run: docker image save "$RUNTIME_IMAGE" | gzip -1 > "$RUNNER_TEMP/runtime.tar.gz"
- uses: actions/upload-artifact@v7
if: env.PUBLISH != 'true'
with:
name: rockchip-runtime
path: ${{ runner.temp }}/runtime.tar.gz
compression-level: 0
retention-days: 1
if-no-files-found: error

images:
needs: runtime
name: Build ${{ matrix.family }} model images
runs-on: ubuntu-24.04-arm
timeout-minutes: 120
strategy:
fail-fast: false
max-parallel: 4
matrix: ${{ fromJSON(needs.runtime.outputs.families) }}
permissions:
contents: read
packages: write
defaults:
run:
working-directory: src/cpp
env:
IMAGE_NAMESPACE: ${{ needs.runtime.outputs.namespace }}
MODEL_FAMILY: ${{ matrix.family }}
steps:
- uses: actions/checkout@v6
with:
persist-credentials: false
lfs: false
sparse-checkout-cone-mode: false
sparse-checkout: |
/.gitattributes
/src/cpp/
/src/rv182x_rk3588_yolo26/video/test.mp4
/src/rk3576_yolov8_pose/video/test.mp4
- uses: actions/setup-python@v6
with:
python-version: '3.12'
- run: python -m pip install 'PyYAML==6.0.3'
- uses: docker/login-action@v4
if: env.PUBLISH == 'true'
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- uses: actions/download-artifact@v7
if: env.PUBLISH != 'true'
with:
name: rockchip-runtime
path: ${{ runner.temp }}
- name: Load the shared runtime
shell: bash
run: |
if [[ "$PUBLISH" == true ]]; then
remote_runtime="$IMAGE_NAMESPACE/runtime:$GITHUB_SHA"
docker pull --platform linux/arm64 "$remote_runtime"
docker image tag "$remote_runtime" "$RUNTIME_IMAGE"
else
docker image load --input "$RUNNER_TEMP/runtime.tar.gz"
fi
- name: Build and verify model packages
shell: bash
run: |
args=()
if [[ -n "$MODEL_ID" ]]; then args+=(--model "$MODEL_ID"); fi
if [[ "$CHECK_N_INT8" == true ]]; then args+=(--size n --precision int8); fi
if [[ "$PUBLISH" == true ]]; then args+=(--publish); fi
python tools/build_images.py --runtime "$RUNTIME_IMAGE" --repository "$IMAGE_NAMESPACE" \
python tools/build_images.py --family "$MODEL_FAMILY" --runtime "$RUNTIME_IMAGE" --repository "$IMAGE_NAMESPACE" \
--revision "$GITHUB_SHA" "${args[@]}"
5 changes: 4 additions & 1 deletion src/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ find_package(PkgConfig REQUIRED)
find_package(Threads REQUIRED)
find_package(nlohmann_json REQUIRED)
pkg_check_modules(AV REQUIRED IMPORTED_TARGET libavformat libavcodec libavutil libavdevice)
pkg_check_modules(SWSCALE REQUIRED IMPORTED_TARGET libswscale)
set(ROCKCHIP_SDK /opt/rockchip CACHE PATH "Rockchip SDK prefix")
find_path(RGA_INCLUDE im2d.hpp HINTS ${ROCKCHIP_SDK}/rga/include REQUIRED)
find_path(RKNN_INCLUDE rknn_api.h HINTS ${ROCKCHIP_SDK}/rknn/include REQUIRED)
Expand All @@ -32,4 +33,6 @@ pybind11_add_module(_native
native/engine/jpeg_preview.cpp)
target_include_directories(_native PRIVATE native ${RGA_INCLUDE} ${RKNN_INCLUDE} ${MPP_INCLUDE})
target_link_libraries(_native PRIVATE PkgConfig::AV Threads::Threads nlohmann_json::nlohmann_json ${RGA_LIB} ${RKNN_LIB} ${MPP_LIB})
install(TARGETS _native LIBRARY DESTINATION rkapi)
pybind11_add_module(_hdmi native/camera.cpp)
target_link_libraries(_hdmi PRIVATE PkgConfig::AV PkgConfig::SWSCALE Threads::Threads)
install(TARGETS _native _hdmi LIBRARY DESTINATION rkapi)
95 changes: 68 additions & 27 deletions src/cpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ working NPU, RGA, and MPP drivers supplied by the board OS.

**1. Start YOLO26 object detection on the board**

```sh
docker run --rm --name cv-api \
```bash
docker run -d --name cv-api --restart unless-stopped \
--privileged -p 8000:8000 \
-v /proc/device-tree/compatible:/proc/device-tree/compatible:ro \
"ghcr.io/seeed-projects/recomputer-rk-cv/yolo26n:rk3588-int8"
ghcr.io/seeed-projects/recomputer-rk-cv/yolo26n:rk3588-int8
```

On an RK3576 board, use the `rk3576-int8` tag.
Pick a model and tag from the [model catalog](#models),
or [build the same image locally](#build-locally). Use a different container
name and host port, such as `-p 8001:8000`, to serve a second model.
Expand Down Expand Up @@ -103,13 +104,25 @@ if metadata["model"]["task"] == "detection":

## Models

YOLO26 ships in sizes `n`, `s`, and `m` for RK3576 and RK3588, with
INT8 and FP16 builds for all seven tasks. Each image serves one model and includes a short demo video.
The catalog contains 84 variants across 21 image names.
The catalog follows the model exports in [Rockchip CV API](https://github.com/Hanzo-Huang/rockchip-cv-api).
It contains 316 INT8 and FP16 variants across 10 families for RK3576 and RK3588.
Each image serves one model and includes demo media for its task.

| Family | Sizes | Tasks |
| --- | --- | --- |
| YOLO26 | `n`, `s`, `m` | Detection, segmentation, pose, oriented boxes, classification, semantic segmentation, depth |
| YOLO11, YOLOv8 | `n`, `s`, `m` | Detection, segmentation, pose, oriented boxes, classification |
| YOLOv5 | `n`, `s`, `m`, plus `s-relu` for detection | Detection, segmentation, classification |
| YOLOv6 | `n`, `s`, `m` | Detection |
| YOLOv7 | `base`, `tiny` | Detection |
| YOLOv10 | `n`, `s`, `m`, `b`, `l`, `x` | Detection |
| YOLOX | `nano`, `s`, `m` | Detection |
| PP-YOLOE | `s`, `m` | Detection |
| YOLO-World | `v2s`, `v2m` | Detection with the model zoo's fixed COCO vocabulary |

All images built from the same code revision share the same ARM64 operating
system, dependencies, C++ engine, HTTP API, and browser code. The final filesystem layer contains model-specific files. A separate layer contains
the selected demo video and its attribution. The common entrypoint loads
the selected demo media and its attribution. The common entrypoint loads
the model manifest bundled at `/opt/model/package.json`.

Image names below use the prefix `ghcr.io/seeed-projects/recomputer-rk-cv/`.
Expand All @@ -120,12 +133,13 @@ Image names below use the prefix `ghcr.io/seeed-projects/recomputer-rk-cv/`.
| Instance segmentation | `yolo26n-seg:rk3588-int8` | `predictions[].mask` |
| Pose estimation | `yolo26n-pose:rk3588-int8` | `predictions[].keypoints` as `[x, y, confidence]` |
| Oriented boxes | `yolo26n-obb:rk3588-int8` | `predictions[].polygon` with four corners |
| Classification | `yolo26n-cls:rk3588-int8` | `classification` with ranked classes |
| Classification | `yolo26n-cls:rk3588-int8` | `classification` with ranked class IDs, names, and scores |
| Semantic segmentation | `yolo26n-sem:rk3588-int8` | `semantic` raster and class labels |
| Depth estimation | `yolo26n-depth:rk3588-int8` | `depth` raster |

Replace `rk3588` with `rk3576` for the other board, or `int8` with `fp16`
to change precision. Run `python3 tools/models.py list` for all image tags
to change precision. For example, use `yolo11n-seg:rk3588-int8` for YOLO11
segmentation. Run `python3 tools/models.py list` for all image tags
and build IDs in the [model catalog](models/).

<details>
Expand All @@ -135,6 +149,9 @@ Masks, semantic maps, and depth maps have `width`, `height`, `box`, and
`runs`. The box locates the raster in the source image. Runs alternate value
and count in row-major order. Semantic values are class IDs. Recover depth
samples with `offset + value * scale`. The value `65536` marks invalid depth.
The YOLO26 depth packages use RGA to resize each frame to the model's full
input size. The live preview colorizes inverse depth, with warmer colors for
nearer regions and a relative scale within each frame.

</details>

Expand Down Expand Up @@ -228,11 +245,27 @@ not start inference. Image or video-frame uploads still run on demand.
`/health` reports whether the pipeline is active, the subscriber count, and
the worker count and core masks when running.

| Tasks | Bundled clip |
| Tasks | Bundled media |
| --- | --- |
| Detection, classification, instance segmentation, semantic segmentation, depth | Street traffic with moving vehicles and foreground/background separation |
| Pose | A full-body squat demonstration |
| Oriented boxes | Aerial footage of boats at different angles |
| Detection | [Street traffic from the YOLO11 showcase, in the existing 1080p YOLO26 example](../rv182x_rk3588_yolo26/video/test.mp4) |
| Depth | [Provided depth demo clip](demo/depth.txt). Warmer colors show nearer regions. Adjust overlay opacity to compare with the video. |
| Pose | [Single-person squat demonstration](demo/pose.txt). The browser smooths matched joints across consecutive frames. |
| Instance segmentation | [YOLOv8 pose showcase](../rk3576_yolov8_pose/video/test.mp4) |
| Oriented boxes | [Official Ultralytics aerial ship photo](demo/ships.txt). Select **Detect ships** to draw rotated boxes on the image. The prediction API returns all model classes. |
| Semantic segmentation | [Street-level urban footage](demo/semantic.txt). Each color shows which pixels belong to a class like road, sidewalk, or vegetation. |
| Classification | [Example photos](demo/photos.txt) and an upload form. The page runs a prediction for each photo the viewer submits. |

Use **Input source** to select the built-in example, a capture device exposed to
the container, or a local photo or video. A board camera opens only when you
start its preview. The browser decodes uploaded videos locally and posts sampled
JPEG frames to the preview endpoint. Uploads and camera streams work across all
seven tasks.
Camera and upload previews use one inference worker per NPU core by default,
with two on RK3576 and three on RK3588. They keep only one frame in flight per
worker and present results in frame order. Set `RK_WORKERS=1` to use a single
context. The preview displays each sampled upload frame with its own result. Built-in
videos draw results only on matching video timestamps. Closing the last live
preview stops its inference. On RK3588, select `rk_hdmirx` to use HDMI IN.

The browser plays the H.264 MP4 and draws model results on a canvas. For a
custom clip, pass `-v "$PWD/input.mp4:/media/input.mp4:ro"` with
Expand All @@ -241,12 +274,13 @@ MP4 without a rotation tag. RTSP and H.264 V4L2 sources still use the MJPEG
preview with the source selected through `RK_SOURCE`.

With a YOLO26 split scores-and-boxes model, the browser applies confidence
filtering and per-class NMS locally. The board sends every valid decoded
filtering and per-class NMS for the built-in clip, board camera, and uploaded
video. The board sends every valid decoded
proposal with its highest-scoring class. It applies no confidence cutoff,
top-k limit, or NMS to this stream. The preview controls affect the current
tab. The prediction API and legacy MJPEG feed use the container's API settings.

The browser reads `GET /api/demo/candidates` as a binary stream. Each
For the built-in clip, the browser reads `GET /api/demo/candidates` as a binary stream. Each
little-endian frame contains a `uint32` payload size in bytes, `uint32` source
width, `uint32` source height, `uint32` video loop index, `float64` media
timestamp in seconds, and `uint64` frame sequence. The payload contains
Expand All @@ -263,7 +297,8 @@ preview and holds a live-source subscription.
### Build locally

Run these commands in `src/cpp` on an ARM64 Docker host. Inference requires
the matching Rockchip board. Leave out `--model` to build the full catalog.
the matching Rockchip board. Use `--family yolo11` in place of `--model` to
build a family, or omit both filters to build the full catalog.

```sh
python3 tools/models.py list
Expand All @@ -273,29 +308,36 @@ python3 tools/build_images.py --runtime rockchip-cv-runtime:local \
--repository rockchip-cv-local --model yolo26n-rk3588-int8
```

Set `IMAGE=rockchip-cv-local/yolo26n:rk3588-int8` in the quick-start command.
Replace the quick-start image reference with `rockchip-cv-local/yolo26n:rk3588-int8`.
In a sparse checkout, include the two existing project clip paths in the table
above. Use `--size n --precision int8` in place of `--model` to check the
n-size INT8 variants on both chips.

### GitHub Actions

The [C++ Rockchip model images workflow](../../.github/workflows/cpp-model-images.yml)
uses a native ARM64 runner with a sparse checkout of `src/cpp`. Pull requests
build and check the full catalog. Changes to this directory or workflow on
`main` publish all 84 variants to GHCR. A manual run accepts one catalog ID
uses native ARM64 runners with sparse checkouts. A shared runtime job builds
the base image, and per-family jobs add the demo media and model packages.
Pull requests check n-size INT8 variants on both chips. Changes to the code,
packaged videos, or workflow on `main` publish all 316 variants to GHCR.
A manual run accepts one catalog ID
or the full catalog when left empty. Manual runs on `main` publish images.

The workflow saves one shared runtime per source commit under
`runtime:<commit-sha>`. Each model uses it as the base, verifies the model
package and native module imports, and checks that its layer list matches the
runtime plus one independent video layer and one model layer. Models that
use the same clip must have the same video layer ID. The workflow builds each video layer once from a deterministic archive.
BuildKit's `ADD --link` keeps the video layer independent so code-only
runtime plus one independent demo media layer and one model layer. The workflow
builds each media layer once from a deterministic archive and reuses it for all
images with the same demo assets.
BuildKit's `ADD --link` keeps the media layer independent so code-only
rebuilds can reuse it. Each model is published with a
`<chip>-<precision>` tag and a `<chip>-<precision>-<commit-sha>` tag.

Each manifest points to an immutable Hugging Face revision. The build
downloads the RKNN model and its metadata, verifies their SHA-256 checksums,
and checks the metadata against the task, chip, class list, and tensor
contract. The repository stores the manifests without the weights.
contract. YOLO-World also downloads and verifies the fixed text embedding
tensor. The repository stores the manifests without the weights.

## Credits

Expand All @@ -307,6 +349,5 @@ The model packages use weights and conversion metadata from
Model manifests and metadata record provenance, license information, and the
SHA-256 checksums used during packaging.

The bundled clips were excerpted or resized and converted to H.264 without
audio. Attributions and license links are included in each image at
`/opt/demo/ATTRIBUTION.txt` and in the [demo directory](demo/).
Demo media sources, attribution, and applicable licenses are recorded in the
image at `/opt/demo/ATTRIBUTION.txt`.
Binary file added src/cpp/demo/depth.mp4
Binary file not shown.
3 changes: 3 additions & 0 deletions src/cpp/demo/depth.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Depth demo footage from Pexels, video 13371634.
Source: https://videos.pexels.com/video-files/13371634/13371634-hd_1920_1080_24fps.mp4
License: https://www.pexels.com/license/
Binary file removed src/cpp/demo/harbor.mp4
Binary file not shown.
4 changes: 0 additions & 4 deletions src/cpp/demo/harbor.txt

This file was deleted.

10 changes: 10 additions & 0 deletions src/cpp/demo/photos.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Dog: Labradorretriever.jpg, by Manofsteel, public-domain dedication.
https://commons.wikimedia.org/wiki/File:Labradorretriever.jpg
Banana: Banana-Single.jpg, by Evan-Amos, CC BY-SA 3.0.
https://commons.wikimedia.org/wiki/File:Banana-Single.jpg
Tennis ball: Tennisball.jpg, by Christian “VisualBeo” Horvat, CC BY-SA 3.0.
https://commons.wikimedia.org/wiki/File:Tennisball.jpg
CC BY-SA 3.0 license: https://creativecommons.org/licenses/by-sa/3.0/
Photos were resized and re-encoded as JPEG. The banana and tennis-ball edits are CC BY-SA 3.0.
ImageNet class names: Keras ImageNet class index, keyed by WordNet synset.
https://storage.googleapis.com/download.tensorflow.org/data/imagenet_class_index.json
Binary file added src/cpp/demo/photos/banana.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/cpp/demo/photos/boats.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/cpp/demo/photos/dog.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading