LoginSignup
3
4

Jetson Nanoで YOLOv5 v6.0を動かす(2023年7月確認版)

Last updated at Posted at 2022-07-21

最新版をご覧ください。

  • Jetson Nano 4GB
  • JetPack 4.6 4.6.1
  • logicool C270N

参考にさせていただきました。

OSの設定

パッケージ一覧の更新

sudo apt update

nanoのインストール

sudo apt install nano

スワップ領域の設定

sudo apt install dphys-swapfile
sudo nano /sbin/dphys-swapfile

/sbin/dphys-sapfile
CONF_MAXSWAP=4096

sudo nano /etc/dphys-swapfile

/etc/dphys-swapfile
CONF_SWAPSIZE=4096
CONF_MAXSWAP=4096

スタックサイズの設定

sudo nano /etc/security/limits.conf

/etc/security/limits.conf
ubuntu hard stack unlimited
ubuntu soft stack unlimited

jtopのインストール

  • jtopはJetsonの状態をリアルタイムで確認・制御するシステム監視ユーティリティです。
  • -H:環境変数HOMEをrootユーザーのホームディレクトリに変更してコマンドを実行します。

sudo apt install python-pip
sudo -H pip install jetson-stats
reboot

jtopを実行し、OpenCVの状態を確認
6INFO -> OpenCV: 4.1.1 compiled CUDA: NO
7INFO -> OpenCV: 4.1.1 with CUDA: NO

OpenCVのインストール

wget https://github.com/Qengineering/Install-OpenCV-Jetson-Nano/raw/main/OpenCV-4-5-5.sh
sudo chmod 755 ./OpenCV-4-5-5.sh
./OpenCV-4-5-5.sh

jtopを実行し、OpenCVの状態を確認
6INFO -> OpenCV: 4.5.5 compiled CUDA: YES
7INFO -> OpenCV: 4.5.5 with CUDA: YES

PyTorchのインストール

  • PyTorchは、Facebookが開発を主導したPython向けの機械学習ライブラリです。
  • gdownは、Google Drive専用のダウンローダーです。
  • --user:管理者権限が必要無い ~/.local下にインストールされます。

sudo apt-get install python3-pip libjpeg-dev libopenblas-dev libopenmpi-dev libomp-dev

sudo -H pip3 install future
※ future-0.18.3

sudo pip3 install -U --user wheel mock pillow
※ mock-5.0.2 pillow-8.4.0 wheel-0.37.1

sudo -H pip3 install testresources
※ pbr-5.11.1 testresources-2.0.1

sudo -H pip3 install --upgrade setuptools
※ setuptools-59.6.0

sudo -H pip3 install Cython
※ Cython-0.29.36

sudo -H pip3 install gdown
※ PySocks-1.7.1 filelock-3.4.1 gdown-4.7.1 importlib-resources-5.4.0 tqdm-4.64.1 zipp-3.6.0

gdown https://drive.google.com/uc?id=1wzIDZEJ9oo62_H2oL7fYTp5_-NffCXzt
sudo -H pip3 install torch-1.9.0a0+gitd69c22d-cp36-cp36m-linux_aarch64.whl
※ dataclasses-0.8 torch-1.9.0a0+gitd69c22d typing-extensions-4.1.1

TorchVisionのインストール

  • TorchVisionは、画像処理におけるデータセット(MNIST、COCO)、モデルアーキテクチャ、画像変換処理から構成されたパッケージです。

gdown https://drive.google.com/uc?id=1Q2NKBs2mqkk5puFmOX_pF40yp7t-eZ32
sudo -H pip3 install torchvision-0.10.0a0+300a8a4-cp36-cp36m-linux_aarch64.whl
※ pillow-8.4.0 torchvision-0.10.0a0+300a8a4

YOLOv5 v6.0のインストール

git clone https://github.com/ultralytics/yolov5.git -b v6.0

  • -bオプションでリリースタグ名を指定してCloneします。

nano requirements.txt

requirements.tx 全ての行をコメントアウトします
# pip install -r requirements.txt

# Base ----------------------------------------
# matplotlib>=3.2.2
# numpy>=1.18.5

途中略

# roboflow
# thop  # FLOPs computation

sudo pip3 install -U seaborn
sudo apt install python3-seaborn
※ python3-seaborn (0.8.0-1)、python3-patsy (0.4.1+git34-ga5b54c2-1ubuntu0.1)

  • Seaborn(シーボーン)とは、Pythonの可視化ライブラリの一つです。
    * -U:パッケージのアップグレード

Successfully installed cycler-0.11.0 kiwisolver-1.3.1 matplotlib-3.3.4 numpy-1.19.5 pandas-1.1.5 pyparsing-3.0.9 python-dateutil-2.8.2 pytz-2022.1 scipy-1.5.4 seaborn-0.11.2 six-1.16.0

YOLOv5の動作確認

  • detect.pyの実行

python3 detect.py

初回起動時はウェイトファイル「yolov5s.pt」がダウンロードされます。

検出結果は「yolov5/runs/detect/exp」内に保存されます(bus.jpg、zidane.jpg)。

  • webカメラから動画を入力して認識を実行(yolov5s.ptを使用)

python3 detect.py --source 0 --imgsz=256 --nosave

Jetson Nano:1 frame:0.063s(15.8fps)

この後は

3
4
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4