Jetson nano快速上手,跑通tiny-yolov2

Jetson nano快速上手

下載鏡像文件

首先我們需要下jetson的鏡像文件,實際上就是一個針對jetson nano優化過的ubuntu系統。 官方推薦是16G的高速tf卡,這裏建議大家最少使用32G。因爲後面加上各種模型數據和庫,再打開swap區可以輕鬆超過20G

大家可以前往下面網站,並通過在左側選中第三欄,紅圈的位置爲鏡像下載地址。https://developer.nvidia.com/embedded/learn/get-started-jetson-nano-devkit#write

 

 

可以看到nv的下載速度還是不錯的。

 

格式化TF

如果你的tf卡之前做過系統安裝盤,或者有mac備份等等,新卡可以跳過這一步。通過官方推薦的SD Memory Card Formatter格式化tf卡。或者你想把tf恢復如初,也可以用這個工具。(tf卡刷了jetson鏡像後插到電腦上會出現十來個u盤盤符)

我們下載官方推薦的etcher工具進行鏡像燒錄。 https://www.balena.io/etcher/

第一項直接選中我們剛剛下載的zip文件,etcher不需要解壓剛剛下載的zip文件,會自動讀取裏面的鏡像文件。

之後就開始漫長的燒錄過程了,如果你的sd卡讀卡器還是USB 2.01.1估計要半個小時以上。USB3.0的讀卡器大約需要10分鐘,注意電腦機箱上藍色的(9p)纔是usb3.0的接口。

當燒錄完成後如果電腦上彈出來一堆盤符這是正常現象,將讀卡器彈出就好了~

首次啓動jetson

tf卡插到jetson主板背面: 之後插上hdmi線,鍵盤鼠標和網線。電源可以選擇micro-usb口,這裏需要使用5V 3A的適配器或充電寶。如果使用外部適配器,請一定要選擇5V輸出的,並且輸出電流在3A以上。 Jetson nanoDC接口只支持5V輸入,請千萬別將5V以上的適配器插到jetson上面。 使用外部適配器還需要閉合dc口後邊的跳線帽。

如果手上有小喵家rosbot主板可以像下面這樣將主板連接到jetson,安裝的時候需要額外的2.5mm銅螺柱,rosbotdc口支持612v的電源輸入。再三強調,千萬不要手滑把高於5v的電源直接查到jetson上。

首次啓動後需要完成ubuntu剩下的安裝過程,除了時區外基本選默認就行了。

 

ubuntulinux不熟的同學請牢記打開終端的快捷鍵是 ctrl+alt+t linux下的圖形化節目我們用的不多,大部分東西都是在命令行下操作~

 

https://zhuanlan.zhihu.com/p/65188026

WiFi 聯網通常需要用到屏幕,鼠標,鍵盤,並需要登錄桌面。但是一般我們沒有多餘的屏幕和鍵鼠,導致每次設置WiFi都需要將PC的外設換來換去。

使用命令行設置WiFi只需要一根1米網線即可解決。

Win10共享網絡設置

首先用網線把Jetson Nano和電腦連接起來。

然後依次打開:控制面板——>網絡和Internet——>網絡和共享中心——>更改適配器設置——>Wlan屬性(或者以太網屬性)——>共享

https://pic4.zhimg.com/80/v2-f9c2a9795d3e577d001209fe5c2eb573_hd.jpg

然後將“允許其他網絡用戶通過此計算機的Internet連接來連接”打鉤。

查找 Jetson Nano IP 地址

使用 Advanced IP Scanner 軟件進行搜索就能找到。

 

使用 SSH 登錄 Jetson Nano

這裏使用 PuTTY 作爲終端,輸入上面找到的Jetson Nano 的IP地址。

Installation

  1. Install dependent libraries.
  2. $ sudo apt update
  3. $ sudo apt install python3-pip protobuf-compiler libprotoc-dev libjpeg-dev cmake
  4. You might need to install Cython alone prior to the other python modules installation. Otherwise "RuntimeError: Running cythonize failed!" might happens at the numpy installation.
$ pip3 install --user cython
  1. Install this application and the dependent modules.
  2. $ git clone https://github.com/tsutof/tiny_yolov2_onnx_cam
  3. $ cd tiny_yolov2_onnx_cam
  4. $ export PATH=$PATH:/usr/local/cuda/bin
  5. $ python3 -m pip install -r requirements.txt

There is the "onnx==1.4.1" restriction in the requirements.txt, because TensorRT dosen't work with ONNX 1.5.x. It seems that ONNX 1.6.0 has no problem with TensorRT. So the version restriction will be changed to "onnx>=1.6.0" in the near future.

Usage

First, clock up your Jetson. Only the nvpmodel is not enough, the jetson_clocks command is also needed. Without the jetson_clocks, "select timeout" error happens at the frame capture.

$ sudo nvpmodel -m 0$ sudo jetson_clocks

The following command starts this application. Press ESC key to exit from this application.

$ python3 tiny_yolov2_onnx_cam.py [-h] [--camera CAMERA_NUM] [--width WIDTH][--height HEIGHT] [--objth OBJ_THRESH] [--nmsth NMS_THRESH]optional arguments: -h, --help            show this help message and exit --camera CAMERA_NUM, -c CAMERA_NUMCamera number, use any negative integer for MIPI-CSI camera--width WIDTH         Capture width--height HEIGHT       Capture height--objth OBJ_THRESH    Threshold of object confidence score (between 0 and 1)
  --nmsth NMS_THRESH    Threshold of NMS algorithm (between 0 and 1)

For Raspberry Pi camera v2, use any negative number as the camera number.

$ python3 tiny_yolov2_onnx_cam.py --camera -1 

For USB Web camera, if you camera is detected as /dev/video1, use 1 as the camera number.

$ python3 tiny_yolov2_onnx_cam.py --camera 1

If your USB Web camera does not support this application's default capture resolution, please change it with the --widht and --height command-line options.

To know the supported resolutions by your camera, the gst-device-monitor-1.0 command is very useful.

結果顯示tiny-yolov2大約顯示8幀

 

Jetson AI第一課

官方的jetson系統燒錄完後首先就是推薦大家使用hello AI進行上手,但是在國內網絡環境下需要做一些額外的工作。這篇教程就是教大家如何在牆內的世界跑起來~

原項目地址: https://github.com/dusty-nv/jetson-inference

jetson-inference正如其名只是調用現有訓練好的模型進行計算,並不存在數據採集訓練的過程,也不需要安裝tensorflowcaffe等庫。jetson nano的鏡像已經內置安裝好了cudacudnnopencv

克隆項目到jetson

由於github比較卡,我們將項目挪到國內gitee上了~

cd ~
git clone https://gitee.com/Kittenbot/jetson-inference.git

接下來我們需要編譯項目,默認使用的都是樹莓派兼容的csi攝像頭,如果大家使用的是usb攝像頭可以到不同的項目.cpp文件下將DEFAULT_CAMERA定義後面的-1改成/dev/video

由於大部分模型都託管在google drive的映射上,所以在大防火牆內運行CMakePreBuild.sh安裝腳本下載模型的時候基本都會超時報錯。這裏我們已經將下載好的模型放到百度盤上了,下載爲data.zip文件。

鏈接: https://pan.baidu.com/s/12DPjN79Jn26EW-gR7cLfMA 提取碼: 5fx8 

大家下載後可以拷貝到u盤上,查到jetson上可以用ubuntu自帶的圖形化解壓工具解壓到jetson-inference下覆蓋原有的data目錄就行了。

接下來我們運行下面的腳本

cd jetson-inference
git submodule update --init

如果大家下載並覆蓋了data文件夾,運行cmake的時候不會重新去網上找模型數據庫。

mkdir build
cd build
cmake ../
make
sudo make install

如果編譯沒錯的話,會在build/aarch64/bin生產各個程序的可執行文件。接下來基本就可以照着 https://github.com/dusty-nv/jetson-inference/blob/master/README.md一步步嘗試jetson nanoai能力了~

例如:

cd jetson-inference/build/aarch64/bin
./imagenet-console orange_0.jpg output_0.jpg

 

發佈了89 篇原創文章 · 獲贊 12 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章