LoginSignup
3
1

More than 1 year has passed since last update.

YOLOv5で物体検出

Posted at

はじめに

YOLOv5を使って物体検出をしてみました。
こちらを参考にしました(というか、そのまんま)。

1. 開発環境

  • Windows 10 + WSL2 (Ubuntu20.04)
  • Python 3.8.5
  • Torch 1.5.1

2. インストール

クローンします。

git clone https://github.com/ultralytics/yolov5

環境を準備します。

python3 -m venv yolov5
cd yolov5
source ./bin/activate

ライブラリ等をインストールします。

まずは、PyTorch。

pip install torch===1.5.1 torchvision===0.6.1 -f https://download.pytorch.org/whl/torch_stable.html

requirements.txtからもろもろインストールします。

pip install -U -r requirements.txt

最後に、weightをダウンロードします。

./weights/download_weights.sh

3. つかってみる

以下を実行すると、イメージ画像 data/images/bus.jpg の物体検出が行われます。
その結果が、runs/detect/exp*/に保存されます。(*は検出を行った回数)

python detect.py --source data/images/bus.jpg

bus.jpg

近所の交差点で撮影した動画も物体検出してみました。

python detect.py --source town.mp4

キャプチャ.PNG

それなりに検出できているようです。

4. さいごに

非常にお手軽に物体検出ができます。学習方法も載っていて、こちらも簡単にできました。他のバージョンのyoloと比べて軽くて速い気がします。

3
1
0

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
1