Linux 36.3 + JetPack v6.0@jetson-inference之目标检测

Linux 36.3 + JetPack v6.0@jetson-inference之目标检测

  • 1. 源由
  • 2. detectnet
    • 2.1 命令选项
    • 2.2 下载模型
    • 2.3 操作示例
      • 2.3.1 单张照片
      • 2.3.2 多张照片
      • 2.3.3 视频
  • 3. 代码
    • 3.1 Python
    • 3.2 C++
  • 4. 参考资料

1. 源由

从应用角度来说,目标检测是计算机视觉里面第二个重要环节。之前的识别示例输出了表示整个输入图像的类别概率。接下来,将专注于目标检测,通过提取边界框来找到帧中各种目标的位置。与图像分类不同,目标检测网络能够在每帧中检测到多个不同的目标。

2. detectnet

detectNet对象接受图像作为输入,并输出检测到的边界框坐标列表以及它们的类别和置信度值。detectNet可以在Python和C++中使用。请参阅下面可供下载的各种预训练检测模型。默认使用的模型是基于MS COCO数据集训练的91类SSD-Mobilenet-v2模型,该模型在Jetson上结合TensorRT实现了实时推理性能。

2.1 命令选项

$ detectnet --help
usage: detectnet [--help] [--network=NETWORK] [--threshold=THRESHOLD] ...input [output]Locate objects in a video/image stream using an object detection DNN.
See below for additional arguments that may not be shown above.positional arguments:input           resource URI of input stream  (see videoSource below)output          resource URI of output stream (see videoOutput below)detectNet arguments:--network=NETWORK     pre-trained model to load, one of the following:* ssd-mobilenet-v1* ssd-mobilenet-v2 (default)* ssd-inception-v2* peoplenet* peoplenet-pruned* dashcamnet* trafficcamnet* facedetect--model=MODEL         path to custom model to load (caffemodel, uff, or onnx)--prototxt=PROTOTXT   path to custom prototxt to load (for .caffemodel only)--labels=LABELS       path to text file containing the labels for each class--input-blob=INPUT    name of the input layer (default is 'data')--output-cvg=COVERAGE name of the coverage/confidence output layer (default is 'coverage')--output-bbox=BOXES   name of the bounding output layer (default is 'bboxes')--mean-pixel=PIXEL    mean pixel value to subtract from input (default is 0.0)--confidence=CONF     minimum confidence threshold for detection (default is 0.5)--clustering=CLUSTER  minimum overlapping area threshold for clustering (default is 0.75)--alpha=ALPHA         overlay alpha blending value, range 0-255 (default: 120)--overlay=OVERLAY     detection overlay flags (e.g. --overlay=box,labels,conf)valid combinations are:  'box', 'lines', 'labels', 'conf', 'none'--profile             enable layer profiling in TensorRTobjectTracker arguments:--tracking               flag to enable default tracker (IOU)--tracker=TRACKER        enable tracking with 'IOU' or 'KLT'--tracker-min-frames=N   the number of re-identified frames for a track to be considered valid (default: 3)--tracker-drop-frames=N  number of consecutive lost frames before a track is dropped (default: 15)--tracker-overlap=N      how much IOU overlap is required for a bounding box to be matched (default: 0.5)videoSource arguments:input                resource URI of the input stream, for example:* /dev/video0               (V4L2 camera #0)* csi://0                   (MIPI CSI camera #0)* rtp://@:1234              (RTP stream)* rtsp://user:pass@ip:1234  (RTSP stream)* webrtc://@:1234/my_stream (WebRTC stream)* file://my_image.jpg       (image file)* file://my_video.mp4       (video file)* file://my_directory/      (directory of images)--input-width=WIDTH    explicitly request a width of the stream (optional)--input-height=HEIGHT  explicitly request a height of the stream (optional)--input-rate=RATE      explicitly request a framerate of the stream (optional)--input-save=FILE      path to video file for saving the input stream to disk--input-codec=CODEC    RTP requires the codec to be set, one of these:* h264, h265* vp8, vp9* mpeg2, mpeg4* mjpeg--input-decoder=TYPE   the decoder engine to use, one of these:* cpu* omx  (aarch64/JetPack4 only)* v4l2 (aarch64/JetPack5 only)--input-flip=FLIP      flip method to apply to input:* none (default)* counterclockwise* rotate-180* clockwise* horizontal* vertical* upper-right-diagonal* upper-left-diagonal--input-loop=LOOP      for file-based inputs, the number of loops to run:* -1 = loop forever*  0 = don't loop (default)* >0 = set number of loopsvideoOutput arguments:output               resource URI of the output stream, for example:* file://my_image.jpg       (image file)* file://my_video.mp4       (video file)* file://my_directory/      (directory of images)* rtp://<remote-ip>:1234    (RTP stream)* rtsp://@:8554/my_stream   (RTSP stream)* webrtc://@:1234/my_stream (WebRTC stream)* display://0               (OpenGL window)--output-codec=CODEC   desired codec for compressed output streams:* h264 (default), h265* vp8, vp9* mpeg2, mpeg4* mjpeg--output-encoder=TYPE  the encoder engine to use, one of these:* cpu* omx  (aarch64/JetPack4 only)* v4l2 (aarch64/JetPack5 only)--output-save=FILE     path to a video file for saving the compressed streamto disk, in addition to the primary output above--bitrate=BITRATE      desired target VBR bitrate for compressed streams,in bits per second. The default is 4000000 (4 Mbps)--headless             don't create a default OpenGL GUI windowlogging arguments:--log-file=FILE        output destination file (default is stdout)--log-level=LEVEL      message output threshold, one of the following:* silent* error* warning* success* info* verbose (default)* debug--verbose              enable verbose logging (same as --log-level=verbose)--debug                enable debug logging   (same as --log-level=debug)

注:关于照片、视频等基本操作,详见: 《Linux 36.3 + JetPack v6.0@jetson-inference之视频操作》

2.2 下载模型

两种方式:

  1. 创建 对象时,初始化会自动下载
  2. 通过手动将模型文件放置到data/networks/目录下

国内,由于“墙”的存在,对于我们这种处于起飞阶段的菜鸟来说就是“障碍”。有条件的朋友可以参考《apt-get通过代理更新系统》进行设置网络。

不过,NVIDIA还是很热心的帮助我们做了“Work around”,所有的模型都已经预先存放在中国大陆能访问的位置:Github - model-mirror-190618

  --network=NETWORK     pre-trained model to load, one of the following:* ssd-mobilenet-v1* ssd-mobilenet-v2 (default)* ssd-inception-v2* peoplenet* peoplenet-pruned* dashcamnet* trafficcamnet* facedetect--model=MODEL         path to custom model to load (caffemodel, uff, or onnx)

根据以上Model方面信息,该命令支持:

  • ssd-mobilenet-v1
  • ssd-mobilenet-v2 (default)
  • ssd-inception-v2
  • peoplenet
  • peoplenet-pruned
  • dashcamnet
  • trafficcamnet
  • facedetect
  • 支持定制模型(需要用到通用的模型文件caffemodel, uff, or onnx)

作为示例,就下载一个SSD-Mobilenet-v2(default)模型

$ mkdir model-mirror-190618
$ cd model-mirror-190618
$ wget https://github.com/dusty-nv/jetson-inference/releases/download/model-mirror-190618/SSD-Mobilenet-v2.tar.gz
$ tar -zxvf SSD-Mobilenet-v2.tar.gz -C ../data/networks
$ cd ..

注:这个模型文件下载要注意,将解压缩文件放置到SSD-Mobilenet-v2目录下。

2.3 操作示例

$ cd build/aarch64/bin/

2.3.1 单张照片

# C++
$ ./detectnet --network=ssd-mobilenet-v2 images/peds_0.jpg images/test/output_detectnet_cpp.jpg
# Python
$ ./detectnet.py --network=ssd-mobilenet-v2 images/peds_0.jpg images/test/output_detectnet_python.jpg

本次CPP和Python执行概率结果一致,不像imagenet有差异。

在这里插入图片描述

2.3.2 多张照片

# C++
$ ./detectnet "images/peds_*.jpg" images/test/peds_output_detectnet_cpp_%i.jpg
# Python
$ ./detectnet.py "images/peds_*.jpg" images/test/peds_output_detectnet_python_%i.jpg

注:多张图片这里就不再放出了,感兴趣的朋友下载代码,本地运行一下即可。

2.3.3 视频

# Download test video
wget https://nvidia.box.com/shared/static/veuuimq6pwvd62p9fresqhrrmfqz0e2f.mp4 -O pedestrians.mp4
# C++
$ ./detectnet ../../../pedestrians.mp4 images/test/pedestrians_ssd_detectnet_cpp.mp4
# Python
$ ./detectnet.py ../../../pedestrians.mp4 images/test/pedestrians_ssd_detectnet_python.mp4

pedestrians

3. 代码

3.1 Python

Import statements
├── import sys
├── import argparse
├── from jetson_inference import detectNet
└── from jetson_utils import videoSource, videoOutput, LogCommand-line argument parsing
├── Create ArgumentParser
│   ├── description: "Locate objects in a live camera stream using an object detection DNN."
│   ├── formatter_class: argparse.RawTextHelpFormatter
│   └── epilog: detectNet.Usage() + videoSource.Usage() + videoOutput.Usage() + Log.Usage()
├── Add arguments
│   ├── input: "URI of the input stream"
│   ├── output: "URI of the output stream"
│   ├── --network: "pre-trained model to load (default: 'ssd-mobilenet-v2')"
│   ├── --overlay: "detection overlay flags (default: 'box,labels,conf')"
│   └── --threshold: "minimum detection threshold to use (default: 0.5)"
└── Parse arguments├── args = parser.parse_known_args()[0]└── Exception handling├── print("")└── parser.print_help()└── sys.exit(0)Create video sources and outputs
├── input = videoSource(args.input, argv=sys.argv)
└── output = videoOutput(args.output, argv=sys.argv)Load object detection network
└── net = detectNet(args.network, sys.argv, args.threshold)# Note: Hard-code paths to load a model (commented out)├── net = detectNet(model="model/ssd-mobilenet.onnx", labels="model/labels.txt", ├──                 input_blob="input_0", output_cvg="scores", output_bbox="boxes", └──                 threshold=args.threshold)Process frames until EOS or user exits
└── while True:├── Capture next image│   └── img = input.Capture()│       └── if img is None: # timeout│           └── continue├── Detect objects in the image│   └── detections = net.Detect(img, overlay=args.overlay)├── Print the detections│   ├── print("detected {:d} objects in image".format(len(detections)))│   └── for detection in detections:│       └── print(detection)├── Render the image│   └── output.Render(img)├── Update the title bar│   └── output.SetStatus("{:s} | Network {:.0f} FPS".format(args.network, net.GetNetworkFPS()))├── Print performance info│   └── net.PrintProfilerTimes()└── Exit on input/output EOS├── if not input.IsStreaming() or not output.IsStreaming():└── break

3.2 C++

#include statements
├── "videoSource.h"
├── "videoOutput.h"
├── "detectNet.h"
├── "objectTracker.h"
└── <signal.h>Global variables
└── bool signal_recieved = false;Function definitions
├── void sig_handler(int signo)
│   └── if (signo == SIGINT)
│       ├── LogVerbose("received SIGINT\n");
│       └── signal_recieved = true;
└── int usage()├── printf("usage: detectnet [--help] [--network=NETWORK] [--threshold=THRESHOLD] ...\n");├── printf("                 input [output]\n\n");├── printf("Locate objects in a video/image stream using an object detection DNN.\n");├── printf("See below for additional arguments that may not be shown above.\n\n");├── printf("positional arguments:\n");├── printf("    input           resource URI of input stream  (see videoSource below)\n");├── printf("    output          resource URI of output stream (see videoOutput below)\n\n");├── printf("%s", detectNet::Usage());├── printf("%s", objectTracker::Usage());├── printf("%s", videoSource::Usage());├── printf("%s", videoOutput::Usage());└── printf("%s", Log::Usage());main function
├── Parse command line
│   ├── commandLine cmdLine(argc, argv);
│   └── if (cmdLine.GetFlag("help"))
│       └── return usage();
├── Attach signal handler
│   └── if (signal(SIGINT, sig_handler) == SIG_ERR)
│       └── LogError("can't catch SIGINT\n");
├── Create input stream
│   ├── videoSource* input = videoSource::Create(cmdLine, ARG_POSITION(0));
│   └── if (!input)
│       ├── LogError("detectnet:  failed to create input stream\n");
│       └── return 1;
├── Create output stream
│   ├── videoOutput* output = videoOutput::Create(cmdLine, ARG_POSITION(1));
│   └── if (!output)
│       ├── LogError("detectnet:  failed to create output stream\n");
│       └── return 1;
├── Create detection network
│   ├── detectNet* net = detectNet::Create(cmdLine);
│   └── if (!net)
│       ├── LogError("detectnet:  failed to load detectNet model\n");
│       └── return 1;
│   └── const uint32_t overlayFlags = detectNet::OverlayFlagsFromStr(cmdLine.GetString("overlay", "box,labels,conf"));
├── Processing loop
│   └── while (!signal_recieved)
│       ├── Capture next image
│       │   ├── uchar3* image = NULL;
│       │   ├── int status = 0;
│       │   ├── if (!input->Capture(&image, &status))
│       │   │   └── if (status == videoSource::TIMEOUT)
│       │   │       └── continue;
│       │   │   └── break; // EOS
│       ├── Detect objects in the frame
│       │   ├── detectNet::Detection* detections = NULL;
│       │   ├── const int numDetections = net->Detect(image, input->GetWidth(), input->GetHeight(), &detections, overlayFlags);
│       │   └── if (numDetections > 0)
│       │       └── LogVerbose("%i objects detected\n", numDetections);
│       │       └── for (int n=0; n < numDetections; n++)
│       │           ├── LogVerbose("\ndetected obj %i  class #%u (%s)  confidence=%f\n", n, detections[n].ClassID, net->GetClassDesc(detections[n].ClassID), detections[n].Confidence);
│       │           ├── LogVerbose("bounding box %i  (%.2f, %.2f)  (%.2f, %.2f)  w=%.2f  h=%.2f\n", n, detections[n].Left, detections[n].Top, detections[n].Right, detections[n].Bottom, detections[n].Width(), detections[n].Height());
│       │           └── if (detections[n].TrackID >= 0)
│       │               └── LogVerbose("tracking  ID %i  status=%i  frames=%i  lost=%i\n", detections[n].TrackID, detections[n].TrackStatus, detections[n].TrackFrames, detections[n].TrackLost);
│       ├── Render outputs
│       │   ├── if (output != NULL)
│       │   │   ├── output->Render(image, input->GetWidth(), input->GetHeight());
│       │   │   ├── char str[256];
│       │   │   ├── sprintf(str, "TensorRT %i.%i.%i | %s | Network %.0f FPS", NV_TENSORRT_MAJOR, NV_TENSORRT_MINOR, NV_TENSORRT_PATCH, precisionTypeToStr(net->GetPrecision()), net->GetNetworkFPS());
│       │   │   ├── output->SetStatus(str);
│       │   │   └── if (!output->IsStreaming())
│       │   │       └── break;
│       └── Print out timing info
│           └── net->PrintProfilerTimes();
├── Destroy resources
│   ├── LogVerbose("detectnet:  shutting down...\n");
│   ├── SAFE_DELETE(input);
│   ├── SAFE_DELETE(output);
│   ├── SAFE_DELETE(net);
└── LogVerbose("detectnet:  shutdown complete.\n");└── return 0;

4. 参考资料

【1】jetson-inference - Locating Objects with DetectNet

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/25056.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

贪心算法05(leetcode435,763,56)

参考资料&#xff1a; https://programmercarl.com/0435.%E6%97%A0%E9%87%8D%E5%8F%A0%E5%8C%BA%E9%97%B4.html 435. 无重叠区间 题目描述&#xff1a; 给定一个区间的集合 intervals &#xff0c;其中 intervals[i] [starti, endi] 。返回 需要移除区间的最小数量&#xff…

开源项目学习——vnote

一、介绍 vnote是一款免费且开源的markdown编辑器&#xff0c;用C开发&#xff0c;基于Qt框架&#xff0c;windows/linux/mac都能用。 二、编译 $ git clone --recursive https://github.com/vnotex/vnote.git $ cd vnote && mkdir build $ cd build $ cmake ../ $ …

鲜为人知的英伟达创始人:早早退出,身价不如黄仁勋零头

内容提要 普里姆因为婚姻纠纷等个人生活的干扰无法专注在工作上&#xff0c;在成立公司的10年后&#xff0c;也就是2003年宣布退休离开英伟达&#xff0c;并在2006年出售剩余的所有英伟达股份&#xff0c;过上不与外界联系、离群索居的生活&#xff0c;在家中鼓捣着如何“拯救…

UML交互图-协作图

概述 协作图和序列图都表示出了对象间的交互作用&#xff0c;但是它们侧重点不同。序列图清楚地表示了交互作用中的时间顺序&#xff0c;但没有明确表示对象间的关系。协作图则清楚地表示了对象间的关系&#xff0c;但时间顺序必须从顺序号获得。序列图常常用于表示方案&#…

【云原生】基于windows环境搭建Docker

目录 一、Docker Desktop搭建 二、前置准备 2.1开启 Hyper-V 2.2 Hyper-V选项看不到问题解决 2.3 开启或升级wsl 三、安装过程 3.1 下载安装包 3.2 安装 Docker Desktop 3.2.1 Docker 图标一直处于starting状态问题解决 3.3 配置仓库与镜像 3.4 docker功能测试 四、…

Android studio CPU 唤醒而同时允许屏幕关闭时

在Android中&#xff0c;如果你想在设备屏幕关闭时保持CPU活跃&#xff08;即不进入深度睡眠&#xff09;&#xff0c;你可以使用PowerManager类来获取一个PARTIAL_WAKE_LOCK。这个WakeLock类型允许设备在屏幕关闭时仍然保持CPU运行和部分硬件&#xff08;如Wi-Fi&#xff09;活…

pip install 出现 Missing dependencies for SOCKS support 问题的解决

问题描述 因为要分析chromadb 源码&#xff0c;clone了一份代码到本地后&#xff0c;需要安装依赖&#xff0c;发现有依赖需要python版本低于3.9,于是用anaconda新建了一个3.8的环境. conda create -n chroma python3.8 conda activate chroma创建成功后&#xff0c;进入源码…

HSC Mailinspector loader.php 任意文件读取漏洞复现(CVE-2024-34470)

0x01 产品简介 HSC Mailinspector是一款远程电子邮件检查工具&#xff0c;支持POP3/IMAP4协议。它允许用户远程扫描最新邮件&#xff0c;并进行浏览、垃圾邮件排除、编辑、删除等操作&#xff0c;无需实际登录邮箱。 0x02 漏洞概述 由于HSC Mailinspector /public/loader.ph…

揭秘:币圈黑科技私钥碰撞器的项目教程玩法,外面竟然收费200+

一、前言&#xff1a;探寻币圈私钥探测器神秘面纱 在风华正茂的币圈&#xff0c;不仅有无数高涨或者暴跌的数字货币&#xff0c;更有许多被誉为“黑科技”的工具备受热议。其中&#xff0c;私钥碰撞器就是这些黑科技中的一员&#xff0c;它能够搜索并碰撞出特定地址的私钥&…

【AI 高效问答系统】机器阅读理解实战内容

⭐️我叫忆_恒心&#xff0c;一名喜欢书写博客的研究生&#x1f468;‍&#x1f393;。 如果觉得本文能帮到您&#xff0c;麻烦点个赞&#x1f44d;呗&#xff01; 近期会不断在专栏里进行更新讲解博客~~~ 有什么问题的小伙伴 欢迎留言提问欧&#xff0c;喜欢的小伙伴给个三连支…

dockerhub不可用临时解决方案

近日&#xff0c;在拉取一些docker hub的镜像的时候死活拉不下来&#xff0c;要么超时&#xff0c;要么无法接站点地址&#xff0c;不管是docker hub,还是国内镜像站&#xff0c;统统都不行了。 经过各大媒体报道&#xff0c;以及自己的亲身验证&#xff0c;才知道&#xff0c…

状态方程ABCD矩阵如何确定例子

状态方程ABCD矩阵如何确定 确定状态空间表示中的状态矩阵A、输入矩阵 B、输出矩阵C 和直通矩阵D,需要从系统的动力学方程出发,并将其转换为状态方程的形式。我们可以通过一个具体的物理系统(如倒立摆系统)来说明这一过程 例子:倒立摆系统 系统描述 考虑一个倒立摆系统…

Ansible——service模块

目录 参数总结 语法示例 1. 启动服务 2. 停止服务 3. 重启服务 4. 重新加载服务 5. 启用服务 6. 禁用服务 7. 使用定时启动选项 8. 查询帮助信息 Playbook示例 1. 启动服务 2. 停止服务 3. 重启服务 4. 重新加载服务 5. 启用服务 6. 禁用服务 service 模块是…

linux线程的同步与互斥

前面我们讲了线程的概念以及如何创建与控制线程&#xff0c;接下来我们来对线程的细节与线程之间的问题进行一些讲解&#xff1b; 1.线程的互斥 互斥就是相互排斥&#xff0c;我们可以理解为对立竞争不相容&#xff1b;线程的互斥则是线程之间在对于临界资源竞争时相互排斥的…

Mac电脑arm64芯片Cocoapods 的 ffi 兼容问题

转载请标明出处&#xff1a;https://blog.csdn.net/donkor_/article/details/139505395 文章目录 前言问题分析解决方案总结 前言 今天在改Flutter项目的时候&#xff0c;构建IOS项目时&#xff0c;Cocoapods报错 Error: To set up CocoaPods for ARM macOS, run: arch -x86_6…

在 ASP.NET Core 中实现速率限制中间件

速率限制是 Web 应用程序安全和性能管理的一个重要方面&#xff0c;有助于防止滥用并确保公平使用资源。在 ASP.NET Core 中&#xff0c;可以通过中间件实现速率限制&#xff0c;从而提供一种集中机制来控制传入请求的速率。本文探讨了速率限制中间件的概念、它在 ASP.NET Core…

web前端构建表单:深入探索与实践

web前端构建表单&#xff1a;深入探索与实践 在web前端开发中&#xff0c;表单的构建是一项至关重要的任务。它不仅关乎用户界面的友好性&#xff0c;更直接影响到用户数据的收集和处理。本文将从四个方面、五个方面、六个方面和七个方面&#xff0c;深入剖析web前端构建表单的…

NG32单片机GPIO口配置方式

目录 一、引言 二、GPIO口基本结构 三、GPIO口配置方式 四、工作原理 五、总结 一、引言 NG32单片机是一款集成度高、功能强大的微控制器。其中&#xff0c;GPIO&#xff08;General Purpose Input/Output&#xff09;口作为单片机与外部设备通信的重要接口&#xff0c;具…

你知道 npmrc 文档吗? ---- npmrc 关键作用介绍

你知道 npmrc 文档吗&#xff1f; ---- npmrc 关键作用介绍 你知道 npmrc 文档吗&#xff1f; ---- npmrc 关键作用介绍如何修改配置呢&#xff1f;日常开放常常需要置哪些信息呢&#xff1f;registry 信息配置限定包认证信息代理配置缓存配置安装行为 参考 你知道 npmrc 文档吗…

mathematica中针对三维图中的颜色和填充透明度进行指定

颜色指定使用的命令为&#xff1a;PlotStyle 填充的透明度使用的命令为&#xff1a;FillingStyle 示例代码&#xff1a; Clear["Global*"] Plot3D[{Sin[x^2 y], Sin[x^2 - y]}, {x, -2, 2}, {y, -2, 2}, PlotStyle -> {Directive[Red, Specularity[White, 100…