LoginSignup
11
11

More than 1 year has passed since last update.

YOLORで動画物体検出やってみた

Last updated at Posted at 2021-07-07

はじめに

物体検出モデルYOLORを使って動画の物体検出をする機会がありましたので、実行までの手順をまとめてみました。

環境

今回使用する環境はGoogle Colaboratoryです。

前準備

今回はGoogle ColaboratoryのGPU環境を使って実行していきます。

  • メニューバーから「ランタイム」→「ランタイムのタイプを変更」をクリック

  • 「ハードウェアのアクセラレータ」のプルダウンからGPUを選択

実行手順

  • Google Driveをマウント
from google.colab import drive
drive.mount('/content/drive')
  • YOLORリポジトリのクローン(クローンは最初の一回のみ)
%cd "drive/My Drive" 
!git clone -b paper https://github.com/WongKinYiu/yolor
%cd yolor
  • 各種ライブラリをインストール(最初の一回のみ)
!pip install -qr requirements.txt
!git clone https://github.com/JunnYu/mish-cuda
%cd mish-cuda
!python setup.py build install
%cd ..
!git clone https://github.com/fbcotter/pytorch_wavelets
%cd pytorch_wavelets
!pip install .
%cd ..
  • YOLORの学習済みモデルをダウンロードする(最初の一回のみ)
!bash scripts/get_pretrain.sh
  • 動画の物体検出を実行

    動画ファイルはPexels(フリー動画サイト)からダウンロードしました

    !python detect.py --source '/content/drive/My Drive/movies/Pexels Videos 3644.mp4' --weights yolor-p6.pt --conf 0.25 --img-size 1280 --device 0
    

    推論後の動画は./runs/detect/expディレクトリに作成されます。

結果

約23秒の動画では、2分53秒で推論ができました。

※ Qiitaに載せられるファイル形式・サイズの都合上、mp4ファイルをgifファイルに変換し、23秒の動画を1秒にカットしています。

  • 動画のカットにはiMovieを使用

  • gif変換に使ったツールはこちら

Pexels-Videos-3644.gif

まとめ

今回は、YOLORを使った動画の物体検出を行いました。

人混みで被写体が小さくても検出できており、ハンドバックなどの持ち物まで検出できているのはかなりすごいなと思いました。

11
11
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
11
11