私的AI研究会 > NCAppVol3

Neural Compute Application を作る 3

 OpenVINO™ ツールキットの学習済みモデルとサンプルプログラムを参考に Neural Compute Application を製作してみる。

※ 最終更新:2021/09/30 

顔追跡アプリケーション

 機械学習で画像から人物の顔を検出し、フレーム間での一致を調べて、追跡する。
しくみの解説ほかサイトから引用 → https://dev.classmethod.jp/articles/face-re-identification/

  

しくみ

 人物の追跡は、2つのモデルを組み合わせることで動作する。

学習済みモデル

識別情報のデータベース

 識別情報にインデックスを付けて、データベース化する。引用サイトによれば「適用する分野(動画の種類)に応じて、ロジックの変更が必要になる」とある。

  1. 類似度0.3以上を適用
     正面から撮影している動画では、比較的安定して顔の識別情報が取れるため、類似度0.3以上は、全て採用する。 同じインデックスが複数になった場合は、類似度の低い方を無効とする。
  2. 類似度0.3以下は追加
     類似度0.3以下の場合、新規の人物が登場したと判断し、インデックスを追加している。
  3. データベース更新
     今回のデータベースには、顔検出の時点の信頼度もデータベースとして追加されている。
     類似度が、0.9以上で、データベースを更新するが、この際、既存のデータの信頼度と比較して、それを超える場合のみ更新としている。 これにより、顔が横を向いていたり、一部隠れていたりした場合の信頼度の低い情報を排除している。

動作環境

「face-tracking.py」

▼ 入力簡易版
▼「face-tracking.py」

「face-tracking2.py」

▲ モデル対応版
  • 実行時に利用できるコマンドオプション
    コマンドオプションデフォールト設定意味
    -h, --help-ヘルプ表示
    -i, --image../../Videos/video005.mp4カメラ(cam)または動画・静止画像ファイル
    -m_dt, --m_detector必須指定IR フォーマットの顔検出モデル
    -m_re, --m_recognition必須指定IR フォーマット顔識別モデル
    -d, --device必須指定デバイス指定 (CPU/MYRIAD)
    --threshold0.5顔検出レベル
    -s, --speedyスピード計測表示 (y/n)
    -o, --outnon処理結果を出力する場合のファイルパス
    $ python3 face-tracking2.py -h
    
    --- Face Tracking 2 ---
    4.5.2-openvino
    OpenVINO inference_engine: 2.1.2021.3.0-2787-60059f2c755-releases/2021/3
    
    usage: face-tracking2.py [-h] [-i IMAGE_FILE] [-m_dt M_DETECTOR]
                             [-m_re M_REIDENTIFICATION] [-d DEVICE]
                             [--threshold FLOAT] [-s SPEED] [-o IMAGE_OUT]
    
    optional arguments:
      -h, --help            show this help message and exit
      -i IMAGE_FILE, --image IMAGE_FILE
                            Absolute path to movie file or cam for camera stream.
      -m_dt M_DETECTOR, --m_detector M_DETECTOR
                            Detector Path to an .xml file with a trained
                            model.Default value is
                            /home/mizutu/model/intel/FP32/face-detection-0200.xml
      -m_re M_REIDENTIFICATION, --m_reidentification M_REIDENTIFICATION
                            Reidentification Path to an .xml file with a trained
                            model.Default value is
                            /home/mizutu/model/intel/FP32/face-reidentification-
                            retail-0095.xml
      -d DEVICE, --device DEVICE
                            Optional. Specify a target device to infer on. CPU,
                            GPU, FPGA, HDDL or MYRIAD is acceptable. The demo will
                            look for a suitable plugin for the device specified.
                            Default value is CPU
      --threshold FLOAT     Threshold for detection.
      -s SPEED, --speed SPEED
                            Speed display flag.(y/n) Default calue is 'y'
      -o IMAGE_OUT, --out IMAGE_OUT
                            Processed image file path. Default value is 'non'
  • 実行結果
    $ python3 face-tracking2.py -i ~/Videos/video004.mp4
    
    --- Face Tracking 2 ---
    4.5.2-openvino
    OpenVINO inference_engine: 2.1.2021.3.0-2787-60059f2c755-releases/2021/3
    
    Face Tracking 2: Starting application...
       - Image File :  /home/mizutu/Videos/video004.mp4
       - m_detect   :  /home/mizutu/model/intel/FP32/face-detection-0200.xml
       - m_redient. :  /home/mizutu/model/intel/FP32/face-reidentification-retail-0095.xml
       - Device     :  CPU
       - Threshold  :  0.5
       - Speed flag   :  y
       - Processed out:  non
    -------------------
    0.9 (224,81)-(247,106)
    0.9 (383,80)-(405,105)
    0.7 (428,104)-(451,130)
    0.6 (286,77)-(309,103)
    0.5 (346,78)-(369,105)
    ====================
    input: 5 DB:5
    persionId:0 0.9999999999999992 conf:0.9354333281517029
    persionId:1 0.9999999999999992 conf:0.8808209300041199
        :
        :
    0.7 (395,69)-(417,95)
    0.6 (234,69)-(256,94)
    ====================
    input: 6 DB:8
    persionId:3 0.5763441346291421 conf:0.9892716407775879
    persionId:4 0.6838168564758221 conf:0.9515051245689392
    persionId:2 0.6512015020161761 conf:0.8927463293075562
    persionId:5 0.5651382396923563 conf:0.8519667983055115
    persionId:1 0.5783784496160931 conf:0.7289977073669434
    persionId:6 0.46591395996438223 conf:0.6266570687294006
    [3 4 2 5 1 6]
    [3 4 2 5 1 6]
    
    FPS average:      18.90
    
     Finished.
  • その他の実行例
    $ python3 face-tracking2.py -i ~/Videos/video001.mp4
    
    --- Face Tracking 2 ---
    4.5.2-openvino
    OpenVINO inference_engine: 2.1.2021.3.0-2787-60059f2c755-releases/2021/3
    
    Face Tracking 2: Starting application...
       - Image File :  /home/mizutu/Videos/video001.mp4
       - m_detect   :  /home/mizutu/model/intel/FP32/face-detection-0200.xml
       - m_redient. :  /home/mizutu/model/intel/FP32/face-reidentification-retail-0095.xml
       - Device     :  CPU
       - Threshold  :  0.5
       - Speed flag   :  y
       - Processed out:  non
    -------------------
    1.0 (169,87)-(191,118)
    0.9 (231,48)-(254,80)
    0.9 (138,48)-(159,76)
    0.7 (263,63)-(287,98)
    ====================
    input: 4 DB:4
    persionId:0 0.9999999999999989 conf:0.9550001621246338
    persionId:1 1.0000000000000002 conf:0.8864630460739136
        :
        ;
    0.8 (178,89)-(208,128)
    0.6 (180,55)-(199,77)
    ====================
    input: 5 DB:6
    persionId:2 0.6509494574753877 conf:0.9551193714141846
    persionId:3 0.4326297020981334 conf:0.9131746888160706
    persionId:1 0.3132622220134052 conf:0.7962853908538818
    persionId:0 0.46704459059827885 conf:0.7910029292106628
    persionId:5 0.36386064408642443 conf:0.6432196497917175
    [2 3 1 0 5]
    [2 3 1 0 5]
    
    FPS average:      22.70
    
     Finished.
  • その他のコマンド入力例 (Command Helper)
    $ cd ~/workspace/demo
    ◦ CPU
    $ python3 face-tracking2.py -i ~/Videos/video004.mp4
    $ python3 face-tracking2.py -i ~/Videos/video001.mp4
    $ python3 face-tracking2.py -i ~/Videos/classroom_m.mp4
    $ python3 face-tracking2.py -i cam
    ◦ NCS2(MYRIAD)
    $ python3 face-tracking2.py -m_dt ~/model/intel/FP16/face-detection-0200.xml -m_re ~/model/intel/FP16/face-reidentification-retail-0095.xml -d MYRIAD
    $ python3 face-tracking2.py -i ~/Videos/video004.mp4 -m_dt ~/model/intel/FP16/face-detection-0200.xml -m_re ~/model/intel/FP16/face-reidentification-retail-0095.xml -d MYRIAD
    $ python3 face-tracking2.py -i ~/Videos/video001.mp4 -m_dt ~/model/intel/FP16/face-detection-0200.xml -m_re ~/model/intel/FP16/face-reidentification-retail-0095.xml -d MYRIAD
    $ python3 face-tracking2.py -i ~/Videos/classroom_m.mp4 -m_dt ~/model/intel/FP16/face-detection-0200.xml -m_re ~/model/intel/FP16/face-reidentification-retail-0095.xml -d MYRIAD
    $ python3 face-tracking2.py -i cam -m_dt ~/model/intel/FP16/face-detection-0200.xml -m_re ~/model/intel/FP16/face-reidentification-retail-0095.xml -d MYRIAD
▼「face-tracking2.py」
▼「model.py」

更新履歴

 

参考資料

 

Last-modified: 2021-09-30 (木) 20:17:10