Linux 36.2@Jetson Orin Nano之Hello AI World!

2024-02-11 12:20

本文主要是介绍Linux 36.2@Jetson Orin Nano之Hello AI World!,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Linux 36.2@Jetson Orin Nano之Hello AI World!

  • 1. 源由
  • 2. Hello AI World!
  • 3. 步骤
    • 3.1 准备阶段
    • 3.2 获取代码
    • 3.3 Python环境
    • 3.4 重点环节
    • 3.5 软件配置
    • 3.6 PyTorch安装
    • 3.7 编译链接
    • 3.8 安装更新
  • 4. 测试
    • 4.1 video-viewer
    • 4.2 detectnet
    • 4.3 演示命令
  • 5. 参考资料
  • 6. 附录 AI模型

1. 源由

AI到底有多神奇???

记得神奇的年代有神奇的语言:“人有多大胆,地有多大产;不怕想不到,就怕做不到。“

暂且不去讨论这句话的背景,深意,以及各种解说。在这里,抓一个发散思维的要点,要能想,要感想!

好了,废话不多说,既然我们有了《Linux 36.2@Jetson Orin Nano基础环境构建》,就来看看用这些AI技术可以有些什么好玩的!

2. Hello AI World!

大体所有的新事物都会有个类似“Hello AI World”的介绍,让更加贴心的让我们快速接触和理解新事物。

  • Linux应用程序之Helloworld入门
  • ubuntu22.04@laptop OpenCV Get Started: 000_hello_opencv

这里也有一个Jetson AI的Hello AI World!。

大致有三种方法:

  1. Setting up Jetson with JetPack
  2. Running the Docker Container
  3. Building the Project from Source

通常来说,最难的就是从源代码来构建。因为程序对于环境的依赖关系,不是三言两语能够简单概括的。

3. 步骤

注:长城防火墙永远是技术的一种疼。遇到麻烦,请大家参考:Github操作网络异常笔记。

3.1 准备阶段

git用来获取最新github上的代码;而cmake主要用来做编译、链接的。

$ sudo apt-get update
$ sudo apt-get install git cmake

3.2 获取代码

获取最新的代码,通常是一个好的方法。不过也未必,最新不等于最好用。

不过我们的习惯是“不买合适的,不买最好的,就买最贵的;不用好用的,就用最新的。”

$ git clone https://github.com/dusty-nv/jetson-inference
$ cd jetson-inference
$ git submodule update --init

3.3 Python环境

Python在AI程序应用上是非常便捷的方法,当然讲效率那就去用C++。这里都Hello World,谁知道有没有Python示例代码。

$ sudo apt-get install libpython3-dev python3-numpy

3.4 重点环节

这里为什么说是重点,因为按照指南做,死活会出现各种编译、链接问题。经过笔者的牛刀小试,已经给各位解决了问题。

以下这些是Hello World必备的编译链接环境:

$ sudo apt-get install nvidia-cuda-dev tensorrt-dev nvidia-jetpack

3.5 软件配置

注:要按照笔者的方式进行CUDA_TOOLKIT_ROOT宏定义,切记!

$ cd jetson-inference    # omit if working directory is already jetson-inference/ from above
$ mkdir build
$ cd build
$ cmake -D CUDA_TOOLKIT_ROOT=/usr/local/cuda ..

3.6 PyTorch安装

注:这个步骤好像并非必须,笔者就没有做。也许是用到的这个demo用不到吧。

$ cd jetson-inference/build
$ ./install-pytorch.sh

3.7 编译链接

$ cd jetson-inference/build          # omit if working directory is already build/ from above
$ make -j$(nproc)  # 多核编译,加快速度

3.8 安装更新

注:在没有完全搞清楚软件包安装路径前,不建议安装。其实在build目录下也可以用。

$ sudo make install
$ sudo ldconfig

编译好的应用程序都在aarch64下。

jetson-inference$ tree build/ -L 1
build/
├── aarch64
├── CMakeCache.txt
├── CMakeFiles
├── cmake_install.cmake
├── docs
├── examples
├── install-pytorch.rc
├── install-pytorch.sh
├── Makefile
├── python
├── tools
├── torch-2.1.0-cp310-cp310-linux_aarch64.whl
├── torchvision-310
└── utils8 directories, 6 files

4. 测试

Jetson Orin Nano的板子用在AI上,最好的应用就是视频图像分析、物体跟踪。

不再献丑了,网上有大佬dusty-nv的讲座,大家自己看下:

S3E1 - Hello AI World Setup

不过,这种东西不过瘾,对吧。所以,我们先介绍两个常用的命令,弄个好玩的视频分析:

4.1 video-viewer

应用与视频的获取,比如:文件/RTP/RTSP/CSI/MIPI等等。

$ ./video-viewer --help
usage: video-viewer [--help] input_URI [output_URI]View/output a video or image stream.
See below for additional arguments that may not be shown above.positional arguments:input_URI       resource URI of input stream  (see videoSource below)output_URI      resource URI of output stream (see videoOutput below)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)

4.2 detectnet

基于DNN的物体分析。

$ ./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)

4.3 演示命令

  1. 网络RTSP摄像头拉流&分析
$ cd jetson-inference/build
$ ./video-viewer --input-codec=h264 rtsp://192.168.78.201:8554/basesoci2c0muxi2c1ov564736
$ ./detectnet --input-codec=h264 rtsp://192.168.78.201:8554/basesoci2c0muxi2c1ov564736
  1. 视频文件播放&分析
$ cd jetson-inference/build
$ ./video-viewer --input-codec=h264  ../../../../TrackingBike.mp4
$ ./detectnet ../../../../TrackingBike.mp4 ../../../../TrackingBike_Detect.mp4

Extreme Mountain Biking FPV Drone Chasing

5. 参考资料

【1】Linux 36.2@Jetson Orin Nano基础环境构建

6. 附录 AI模型

detectNet 中有不少模型可供选择,默认情况: ssd-mobilenet-v2

  • ssd-mobilenet-v1
  • ssd-mobilenet-v2 (default)
  • ssd-inception-v2
  • peoplenet
  • peoplenet-pruned
  • dashcamnet
  • trafficcamnet
  • facedetect
$ cd jetson-inference/tools
$ ./download-models.sh

在这里插入图片描述

这篇关于Linux 36.2@Jetson Orin Nano之Hello AI World!的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/699761

相关文章

Linux线程之线程的创建、属性、回收、退出、取消方式

《Linux线程之线程的创建、属性、回收、退出、取消方式》文章总结了线程管理核心知识:线程号唯一、创建方式、属性设置(如分离状态与栈大小)、回收机制(join/detach)、退出方法(返回/pthr... 目录1. 线程号2. 线程的创建3. 线程属性4. 线程的回收5. 线程的退出6. 线程的取消7.

Linux下进程的CPU配置与线程绑定过程

《Linux下进程的CPU配置与线程绑定过程》本文介绍Linux系统中基于进程和线程的CPU配置方法,通过taskset命令和pthread库调整亲和力,将进程/线程绑定到特定CPU核心以优化资源分配... 目录1 基于进程的CPU配置1.1 对CPU亲和力的配置1.2 绑定进程到指定CPU核上运行2 基于

golang程序打包成脚本部署到Linux系统方式

《golang程序打包成脚本部署到Linux系统方式》Golang程序通过本地编译(设置GOOS为linux生成无后缀二进制文件),上传至Linux服务器后赋权执行,使用nohup命令实现后台运行,完... 目录本地编译golang程序上传Golang二进制文件到linux服务器总结本地编译Golang程序

Linux下删除乱码文件和目录的实现方式

《Linux下删除乱码文件和目录的实现方式》:本文主要介绍Linux下删除乱码文件和目录的实现方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录linux下删除乱码文件和目录方法1方法2总结Linux下删除乱码文件和目录方法1使用ls -i命令找到文件或目录

Linux在线解压jar包的实现方式

《Linux在线解压jar包的实现方式》:本文主要介绍Linux在线解压jar包的实现方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录linux在线解压jar包解压 jar包的步骤总结Linux在线解压jar包在 Centos 中解压 jar 包可以使用 u

linux解压缩 xxx.jar文件进行内部操作过程

《linux解压缩xxx.jar文件进行内部操作过程》:本文主要介绍linux解压缩xxx.jar文件进行内部操作,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、解压文件二、压缩文件总结一、解压文件1、把 xxx.jar 文件放在服务器上,并进入当前目录#

Linux系统性能检测命令详解

《Linux系统性能检测命令详解》本文介绍了Linux系统常用的监控命令(如top、vmstat、iostat、htop等)及其参数功能,涵盖进程状态、内存使用、磁盘I/O、系统负载等多维度资源监控,... 目录toppsuptimevmstatIOStatiotopslabtophtopdstatnmon

在Linux中改变echo输出颜色的实现方法

《在Linux中改变echo输出颜色的实现方法》在Linux系统的命令行环境下,为了使输出信息更加清晰、突出,便于用户快速识别和区分不同类型的信息,常常需要改变echo命令的输出颜色,所以本文给大家介... 目python录在linux中改变echo输出颜色的方法技术背景实现步骤使用ANSI转义码使用tpu

linux hostname设置全过程

《linuxhostname设置全过程》:本文主要介绍linuxhostname设置全过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录查询hostname设置步骤其它相关点hostid/etc/hostsEDChina编程A工具license破解注意事项总结以RHE

Linux中压缩、网络传输与系统监控工具的使用完整指南

《Linux中压缩、网络传输与系统监控工具的使用完整指南》在Linux系统管理中,压缩与传输工具是数据备份和远程协作的桥梁,而系统监控工具则是保障服务器稳定运行的眼睛,下面小编就来和大家详细介绍一下它... 目录引言一、压缩与解压:数据存储与传输的优化核心1. zip/unzip:通用压缩格式的便捷操作2.