EdgeTAM for RK3588: video object tracking from a click or a box

Compiled models (.rnpu) for the Rockchip RK3588 / RK3588S NPU, ready to load. They are fp16 builds for the NPU stack of RCDL, a C++17 / Python library for vision and speech on these boards. RCDL's own compiler made them from ONNX, and its own runtime runs them by driving the rknpu kernel driver directly. That means no librknnrt and no rknn-toolkit2, only the rknpu driver the board image already has. There is no .rknn build of these models. The stack is described in docs/OPEN_NPU.md.

Upstream: EdgeTAM. You give one click or one box on a frame. It returns the object's mask on that frame and on every later one, and says whether the object is there at all.

Redistributable, including commercially. EdgeTAM is Apache-2.0 on the code and on the weights. See Licence.

Files

file what it is size
edgetam_enc_1024_fp16.rnpu frame encoder: 1024×1024 uint8 RGB → the frame's features, once a frame 10.4 MB
edgetam_memattn_1024_fp16.rnpu memory attention: the frame's features against the memory 90.3 MB
edgetam_dec_p2_fp16.rnpu mask decoder with 2 prompt points: a click, and every tracked frame 29.7 MB
edgetam_dec_p3_fp16.rnpu mask decoder with 3 prompt points: a box 29.7 MB
edgetam_memenc_1024_fp16.rnpu memory encoder: a frame and its mask → 512 memory tokens 7.1 MB

EdgeTAM's own predictor grows its memory as the video goes on. Here the five models have fixed shapes (scripts/edgetam_export.py), and rcdl.VideoObjectTracker keeps the memory between frames: the prompted frame, the six latest frames and 16 object pointers, with absent ones masked. Masks come back in source pixels.

Measured

Against EdgeTAM's reference predictor on its own frames (two videos, 25 frames each), the tracker built from the exported models gives the predictor's masks (IoU 1.000). These NPU builds reach a mean mask IoU of 0.988 and 0.995.

RCDL's benchmark puts a box around a person in bus.jpg, then tracks 10 more frames of the photo under a known zoom and pan, from memory alone:

RK3588S RK3588
one tracked frame (four of the five models) 897.5 ms 882.6 ms
mask IoU with the known motion min 0.943, mean 0.949 min 0.943, mean 0.949

These numbers are from RCDL 0.3.0 packages on its own NPU runtime, with every model on one NPU core and NPU driver 0.9.8 (BSP kernels 6.1.118 and 6.1.141), under the performance CPU governor. With the models spread over all three cores (core=rcdl.NpuCore.ALL), a tracked frame took about 490 ms on the RK3588. Most of a frame is the memory attention: 4096 queries against the frame itself and up to 3648 memory tokens. The boards default to schedutil, which clocks the CPU down while it waits for the NPU. Under it, tasks that alternate NPU and CPU work measured up to about four times slower.

Use it

On the board (linux-aarch64), with RCDL 0.3.1 or newer:

conda create -n rcdl -c https://mirrors.ruis.ai/conda -c conda-forge rcdl
conda activate rcdl
curl -LO https://huggingface.co/ruisv/rcdl-edgetam/resolve/main/edgetam_enc_1024_fp16.rnpu
curl -LO https://huggingface.co/ruisv/rcdl-edgetam/resolve/main/edgetam_memattn_1024_fp16.rnpu
curl -LO https://huggingface.co/ruisv/rcdl-edgetam/resolve/main/edgetam_dec_p2_fp16.rnpu
curl -LO https://huggingface.co/ruisv/rcdl-edgetam/resolve/main/edgetam_dec_p3_fp16.rnpu
curl -LO https://huggingface.co/ruisv/rcdl-edgetam/resolve/main/edgetam_memenc_1024_fp16.rnpu
import cv2, numpy as np, rcdl

t = rcdl.VideoObjectTracker.from_files(
    "edgetam_enc_1024_fp16.rnpu", "edgetam_memattn_1024_fp16.rnpu",
    "edgetam_dec_p2_fp16.rnpu", "edgetam_dec_p3_fp16.rnpu",
    "edgetam_memenc_1024_fp16.rnpu")     # core=rcdl.NpuCore.ALL: all three NPU cores

# A clip with a known motion: bus.jpg zooming in 2% and panning 6 px left a frame.
img = cv2.imread("bus.jpg")
H, W = img.shape[:2]

def warp(i):
    a = cv2.getRotationMatrix2D((W / 2, H / 2), 0, 1.0 + 0.02 * i)
    a[0, 2] -= 6 * i
    return a

frames = [cv2.warpAffine(img, warp(i), (W, H), flags=cv2.INTER_LINEAR,
                         borderMode=cv2.BORDER_REFLECT) for i in range(11)]

first = t.start(frames[0], box=(222, 408, 343, 855))   # a person, source pixels
mask0 = first.data                                       # (h, w) uint8, 0 and 1
print(f"frame 0: {int(mask0.sum())} px in the mask")
ious = []
for i in range(1, len(frames)):
    m = t.track(frames[i])                               # from memory, no prompt
    want = cv2.warpAffine(mask0, warp(i), (W, H), flags=cv2.INTER_NEAREST) > 0
    got = m.data > 0
    ious.append((want & got).sum() / max(1, (want | got).sum()))
    print(f"frame {i}: present={m.present}, IoU with the known motion {ious[-1]:.3f}")
print(f"mean IoU {np.mean(ious):.3f}")

bus.jpg is in RCDL's repository under data/images/.

What to know before deploying

It takes most of a second a frame. At about 0.9 s a tracked frame on one core, and 0.49 s on three, it suits following an object through sampled frames rather than every frame of a live stream.

A box or a click. Prompt with start(frame, box=(x1, y1, x2, y2)) or start(frame, point=(x, y)), in source pixels. The benchmark above uses a box. RCDL's board test follows a moving disc from either, at an IoU above 0.9 on every frame. There is one prompt per track: calling start() again begins a new one.

.present says whether the object is there. It is false where the model judges the object gone, occluded or out of frame, and the mask is then empty. .iou is the decoder's own estimate of the mask's quality.

Frames are resized on the CPU by default. RGA's upscaling lands the picture about a source pixel off OpenCV's bilinear resize, and a mask's edge follows it. A small object's mask agreed with the reference predictor at IoU 0.98 through the CPU and 0.89 through RGA. from_files(..., backend="auto") lets RGA do it.

These files need RCDL's NPU stack. It runs on RK3588 / RK3588S under the Rockchip BSP kernels' rknpu driver (0.9.8). It has been verified on two boards and two kernels (6.1.118, 6.1.141). The rocket driver of mainline kernels is not supported. The stack is marked experimental, and the .rnpu format may still change.

Licence

Apache-2.0, on the EdgeTAM code and on its weights.

RCDL itself is Apache-2.0 and is unrelated to these terms. It is a general-purpose runtime that loads any .rnpu or .rknn. The licence above applies to these weights and these compiled files only.

The input contract for every model is in RCDL's docs/MODELS.md. The licence status of every model RCDL has verified is in model_zoo/.

中文说明

简介

这是 EdgeTAM 视频目标跟踪模型为 Rockchip RK3588 / RK3588S NPU 编译好的文件 (.rnpu),下载即可加载。它们是 RCDL 自有 NPU 栈的 fp16 构建:由 RCDL 自己的编译器从 ONNX 编译,再由它自己的运行时直接 驱动 rknpu 内核驱动来运行。不需要 librknnrt,也不需要 rknn-toolkit2,只要板子 镜像自带的 rknpu 驱动即可。这些模型没有 .rknn 版本。整套 NPU 栈的介绍见 docs/OPEN_NPU.zh.md。

上游是 EdgeTAM。在一帧上点一下或 框一下,它就给出目标在这一帧和之后每一帧的掩码,并告诉你目标是否还在画面里。

可以再分发,包括商用。EdgeTAM 的代码和权重都是 Apache-2.0。

文件

  • edgetam_enc_1024_fp16.rnpu(10.4 MB):帧编码器,输入 1024×1024 的 uint8 RGB,输出这一帧的特征,每帧运行一次。
  • edgetam_memattn_1024_fp16.rnpu(90.3 MB):记忆注意力,用这一帧的特征去查询记忆。
  • edgetam_dec_p2_fp16.rnpu(29.7 MB):2 个提示点的掩码解码器,用于点击,也用于每个跟踪帧。
  • edgetam_dec_p3_fp16.rnpu(29.7 MB):3 个提示点的掩码解码器,用于框。
  • edgetam_memenc_1024_fp16.rnpu(7.1 MB):记忆编码器,把一帧和它的掩码编码成 512 个记忆 token。

EdgeTAM 原本的预测器会随视频变长不断扩大记忆。这里五个模型都是固定形状 (scripts/edgetam_export.py),记忆由 rcdl.VideoObjectTracker 在帧与帧之间 维护:提示帧、最近 6 帧和 16 个目标指针,缺失的部分会被屏蔽。掩码按原图像素返回。

实测

  • 与 EdgeTAM 参考预测器在它自己的帧上对比(两段视频,各 25 帧):用导出的模型搭起来的跟踪器与参考预测器的掩码完全一致(IoU 1.000);这些 NPU 构建的平均掩码 IoU 为 0.988 和 0.995。
  • RCDL 基准测试在 bus.jpg 上框住一个人,再把照片按已知的缩放和平移生成 10 帧,只靠记忆跟踪:每个跟踪帧(五个模型中运行四个)在 RK3588S 上 897.5 ms,RK3588 上 882.6 ms;与已知运动对比的掩码 IoU 最低 0.943,平均 0.949,两块板子结果相同。
  • 测试条件:RCDL 0.3.0 的 conda 包,自有 NPU 运行时,所有模型都在单个 NPU 核心上,NPU 驱动 0.9.8(BSP 内核 6.1.118 和 6.1.141),CPU 调频策略为 performance。模型分摊到三个核心(core=rcdl.NpuCore.ALL)时,RK3588 每个跟踪帧约 490 ms。大部分时间花在记忆注意力上:4096 个查询,对象是这一帧本身和最多 3648 个记忆 token。板子默认的 schedutil 会在等待 NPU 时降低 CPU 频率,NPU 与 CPU 交替工作的任务在它下面最多慢到约四倍。

用法

需要 RCDL 0.3.1 或更新版本,从上面的 conda 频道安装。用法见上面的代码:下载五个 模型,把 bus.jpg 按已知的缩放和平移做成 11 帧,在第一帧框住一个人,之后每帧只靠 记忆跟踪,并打印每帧掩码与已知运动的 IoU。bus.jpg 在 RCDL 仓库的 data/images/ 目录下。

部署前须知

  • 每帧接近一秒。 单核每个跟踪帧约 0.9 s,三核约 0.49 s,适合在抽样的帧上跟踪目标,而不是处理实时视频的每一帧。
  • 框或点击都可以。 用 start(frame, box=(x1, y1, x2, y2)) 或 start(frame, point=(x, y)) 提示,坐标为原图像素。上面的基准测试用的是框;RCDL 的板上测试无论点击还是框,都能跟住一个移动的圆盘,每帧 IoU 都在 0.9 以上。一次提示对应一条轨迹,再次调用 start() 就开始新的跟踪。
  • .present 表示目标是否还在。 模型判断目标消失(被遮挡或出画)时为 false,此时掩码为空。.iou 是解码器自己对掩码质量的估计。
  • 帧的缩放默认在 CPU 上做。 RGA 放大时画面会比 OpenCV 的双线性缩放偏移约一个原图像素,掩码边缘也会跟着偏。一个小目标的掩码与参考预测器的 IoU,走 CPU 时是 0.98,走 RGA 时是 0.89。from_files(..., backend="auto") 可以让 RGA 来做缩放。
  • 这些文件只能在 RCDL 的 NPU 栈上运行。 支持 RK3588 / RK3588S,使用 Rockchip BSP 内核的 rknpu 驱动(0.9.8),已在两块板子、两个内核(6.1.118、6.1.141)上验证;主线内核的 rocket 驱动不支持。这套栈仍处于实验阶段,.rnpu 格式以后还可能改变。

许可证

EdgeTAM 的代码和权重都是 Apache-2.0。RCDL 本身是 Apache-2.0,与上述条款无关; 上面的许可证只适用于这些权重和编译后的文件。各模型的输入约定见 RCDL 的 docs/MODELS.md, RCDL 核实过的所有模型的许可证情况见 model_zoo/。

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support