如何在Seeed Studio reComputer上使用Jetson平台服务运行零样本检测
所有教程都免费开源,请动动小手点个小星星https://github.com/Seeed-Projects/jetson-examples
简介
生成式AI视觉变换器(如CLIP)使得构建零样本检测模型成为可能,这种模型能够进行开放词汇物体检测。这意味着,模型不受预定义类别的限制,可以根据用户在运行时配置的目标进行检测。零样本检测AI服务能够利用Jetson服务快速部署生成式AI,用于视频直播输入的开放词汇检测。该零样本检测AI服务通过REST API端点控制流输入和检测对象。
本教程将指导如何在reComputer J4012上运行零样本检测。
如何在reComputer上使用Jetson平台服务运行零样本检测
要求
在开始设置过程之前,请确保您的系统满足以下前提条件:
- 运行Ubuntu
22.04
或更高版本的reComputer J4012 Orin NX 16G。 - 驱动版本:
535.113.01
,Jetpack版本:6.0
,CUDA版本:12.2
。 - 确保已安装JetPack和相关的Jetson服务包。
sudo apt-get install nvidia-jetpack sudo apt install nvidia-jetson-services
- 可以通过RTSP流传输IP摄像头或本地视频(推荐使用我们的NVStreamer教程进行RTSP流传输)。
开始使用
步骤 1:从NGC下载应用程序包 zero_shot_detection-1.1.0.tar.gz
到Jetson。使用此链接:NGC参考工作流和资源。你需要输入NGC凭证。在页面上,使用**Download
**菜单(右上角)中的选项之一:
tar -xvf zero_shot_detection-1.1.0.tar.gz
cd ~/zero_shot_detection/example_1
步骤 2:零样本检测AI服务将使用 jetson-ingress
和 jetson-redis
服务。你需要配置 jetson-ingress
服务以公开零样本检测的REST API。将提供的默认配置复制到相应的服务配置目录。
sudo cp config/zero_shot_detection-nginx.conf /opt/nvidia/jetson/services/ingress/config
步骤 3:运行基础服务。
sudo systemctl start jetson-monitoring
sudo systemctl start jetson-sys-monitoring
sudo systemctl start jetson-gpu-monitoring
步骤 4:验证平台入口配置文件(用于监控服务)中的所有行在以下文件中均已取消注释:
/opt/nvidia/jetson/services/ingress/config/platform-nginx.conf
步骤 5:启动API网关以访问监控仪表板。
sudo systemctl restart jetson-ingress
sudo systemctl restart jetson-redis
sudo systemctl restart jetson-vst
步骤 6:启动零样本检测AI服务。
sudo docker compose up -d
要检查所有必需的容器是否已启动,你可以运行以下命令:
sudo docker ps
添加RTSP流输入
你可以首先为零样本检测模型添加RTSP流,使用以下curl命令。建议使用NVStreamer教程进行流传输。
- 步骤 1:将
0.0.0.0
替换为你的Jetson IP,将liveStreamUrl
链接替换为你的RTSP链接,然后在终端中输入以下命令:curl --location 'http://0.0.0.0:5010/api/v1/live-stream' \ --header 'Content-Type: application/json' \ --data '{ "liveStreamUrl": "rtsp://0.0.0.0:31554/nvstream/root/store/nvstreamer_videos/car.mp4" }'
注意:除了curl命令,你还可以直接通过API文档页面测试REST API,该页面在零样本检测服务启动时可通过http://0.0.0.0:5010/docs
访问。
-
步骤 2:执行第一个步骤后,将返回一个ID。你需要记录此ID以在后续步骤中使用。
{"id": "a782e200-eb48-4d17-a1b9-5ac0696217f7"}
你也可以使用以下命令稍后获取ID:
curl --location 'http://0.0.0.0:5010/api/v1/live-stream'
要根据ID删除流,可以使用以下命令:
curl --location --request DELETE 'http://0.0.0.0:5010/api/v1/live-stream/{id}'
添加检测类别
零样本检测模型可以在运行时更新其检测类别。此端点接受要检测的对象列表和关联的阈值。阈值是检测的敏感度。较高的值将减少误报。较低的值将增加误报。目前此服务仅支持1个流,但将来此API将支持多流。
- 步骤 1:将
0.0.0.0
替换为你的reComputer IP地址,修改objects
以包含你需要检测的对象(最多十个),为每个类别设置thresholds
,并使用前一步返回的id
。完成命令后,在终端中输入以下内容:curl -X 'POST' \ 'http://192.168.49.101:5010/api/v1/detection/classes' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -d '{ "objects": [ "a car", "a people" ], "thresholds": [ 0.2, 0.04 ], "id": "a782e200-eb48-4d17-a1b9-5ac0696217f7" }'
查看RTSP流结果
检测输出将通过rtsp://reComputer_ip:5011/out
进行流式传输。我们提供了一个Python脚本用于可视化视频流输出。你需要提前安装opencv-python库,然后运行以下Python脚本:
- 步骤 1:安装opencv-python库:
pip install opencv-python
- 步骤 2:运行以下Python脚本:
import cv2 rtsp_url = "rtsp://reComputer_ip:5011/out" cap = cv2.VideoCapture(rtsp_url) if not cap.isOpened(): print("Cannot open RTSP stream") exit() while True: ret, frame = cap.read() if not ret: print("Failed to retrieve frame") break cv2.imshow('RTSP Stream', frame) if cv2.waitKey(1) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows()
关闭服务
要停止零样本检测服务,请在compose.yaml
文件所在目录中运行以下命令:
sudo docker compose down
更多详情
-
一键部署项目: Jetson examples
内容贡献者
Seeed Studio–Zhu Yaohui