3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Yolo, Darknetを用いたリアルタイム物体検出(QuickStart用リポジトリ作成)

Posted at

リアルタイムに物体検出したくなった

カメラに映っている内容から、任意のアクションをフックするようなシステムを構築したく調査してみた
その際、公式のDarknetでは素直にリアルタイム検出ができず後述する諸問題がでてきたため、修正版のdarknetとしてリポジトリをフォークした
問題点のメモとしてこの記事にまとめておく。

成果物

フォークしたDarknetがこちら

下記のページから、いつもありがたく使わせてもらっています
みんなにOSSを見てもらいたい人の為に、GitHubリポジトリのOGP的画像を自動生成してくれるサービスを作った

つまづいた内容

Githubに行ったけど、何をしていいかわからない問題

下記がdarknetのgithubだが、READMEがさらっとしか書いていなかった...
https://github.com/pjreddie/darknet

また、別サイトのリンクもあるが、こちらにもpythonという文字列が見つからず。
pythonで動かしたい場合の方法が一切わからない状況だった

ソースそのままじゃうごかない問題

下記のpython用のコードを見つけて実行してみるとまぁまぁエラーが出る
https://github.com/pjreddie/darknet/blob/master/python/darknet.py

python3じゃ動かないぜ?のエラー

python2系の表記やないですか(絶望

実行してみた
(py) $python python/darknet.py 
  File "python/darknet.py", line 154
    print r
          ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(r)?

下記のように修正し解決

print(r)

libdarknetないで?のエラー

これはdarknetをビルドすることで解決
方法はインストールディレクトリでmakeってするだけ

OSError: dlopen(libdarknet.so, 10): image not found

型おかしいで?のエラー

Cのコードにpythonの文字列を渡してあげるときに、b"文字列"って書くとのこと
エラー内容: 「ctypes.ArgumentError: argument 1: : wrong type」
参考: https://github.com/pjreddie/darknet/issues/241

そんな設定ファイルないで?のエラー

Couldn't open file: cfg/tiny-yolo.cfg

とりま新しげなやつも同じディレクトリにあるので、下記のファイルに変更した(適当

cfg/yolov3-tiny.cfg 

重みないよ?のエラー

Loading weights from tiny-yolo.weights...Couldn't open file: tiny-yolo.weights

下記コマンドで(cfgに併せて適当なものを)取得して解決

wget https://pjreddie.com/media/files/yolov3-tiny.weights

上記により、画像一枚分の物体検出が可能

しかし、リアルタイムに物体検出がしたい

そのままのDarknetでは、OpenCVから取得したリアルタイム画像を扱うことができない。
下記のIssueにて回避策も提示されているが、darknetのソースに修正を加えるもののため面倒
https://github.com/pjreddie/darknet/issues/289

上記までの課題部分を解決し、すぐにdarknetを試せるようFixしたDarknetを下記の通り公開中(2回目)

上記で述べた問題点を改修して、READMEにQuick Start方法を記載してあります。

3
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?