マルチカメラ・マルチターゲット Python* デモ#

このデモでは、OpenVINO™ を使用してマルチカメラ・マルチターゲット (人や車両など) デモを実行する方法を示します。

どのように動作するか#

デモでは、中間表現 (IR) 形式の次のモデルが想定されています:

  • 物体検出モデルまたはオブジェクト・インスタンスのセグメント化モデル

  • 物体再識別モデル

デモ・アプリケーションは入力として次を受け取ります:

  • 1 つまたは複数のビデオファイルへのパス

  • Web カメラの数値インデックス

デモのワークフローは次のとおりです:

  1. アプリケーションは、Web カメラ/ビデオからフレームのタプルを 1 つずつ読み取ります。タプル内の各フレームに対して物体検出器を実行し、検出された物体ごとに再識別モデルを使用して埋め込みを抽出します。

  2. すべての埋め込みはトラッカーに渡され、各物体に ID が割り当てられます。

  3. このデモでは、結果として得られる境界ボックスと、追跡中に割り当てられる一意のオブジェクト ID を視覚化します。

: デフォルトでは、Open Model Zoo のデモは BGR チャネル順序での入力を期待します。RGB 順序で動作するようにモデルをトレーニングした場合は、サンプルまたはデモ・アプリケーションでデフォルトのチャネル順序を手動で再配置するか、--reverse_input_channels 引数を指定したモデル・オプティマイザー・ツールを使用してモデルを再変換する必要があります。引数の詳細については、[前処理計算の埋め込み](@ref openvino_docs_MO_DG_Additional_Optimization_Use_Cases) の入力チャネルを反転するセクションを参照してください。

実行の準備#

デモの入力画像またはビデオファイルについては、Open Model Zoo デモの概要デモに使用できるメディアファイルのセクションを参照してください。デモでサポートされるモデルリストは、<omz_dir>/demos/multi_camera_multi_target_tracking_demo/python/models.lst ファイルにあります。このファイルは、モデル・ダウンローダーおよびコンバーターのパラメーターとして使用され、モデルをダウンロードし、必要に応じて OpenVINO IR 形式 (*.xml + *.bin) に変換できます。

モデル・ダウンローダーの使用例:

omz_downloader --list models.lst

モデル・コンバーターの使用例:

omz_converter --list models.lst

サポートされるモデル#

  • instance-segmentation-security-0002

  • instance-segmentation-security-0091

  • instance-segmentation-security-0228

  • instance-segmentation-security-1039

  • instance-segmentation-security-1040

  • person-detection-retail-0013

  • person-reidentification-retail-0277

  • person-reidentification-retail-0286

  • person-reidentification-retail-0287

  • person-reidentification-retail-0288

  • vehicle-reid-0001

: 各種デバイス向けのモデル推論サポートの詳細については、インテルの事前トレーニング・モデルのデバイスサポートパブリックの事前トレーニング・モデルのデバイスサポートの表を参照してください。

実行する#

コマンドライン引数#

-h オプションを指定してアプリケーションを実行すると、使用方法が表示されます:

usage: multi_camera_multi_target_tracking_demo.py [-h] -i INPUT [INPUT ...]
                                 [--loop] [--config CONFIG] 
                                 [--detections DETECTIONS] 
                                 [-m M_DETECTOR] 
                                 [--t_detector T_DETECTOR] 
                                 [--m_segmentation M_SEGMENTATION] 
                                 [--t_segmentation T_SEGMENTATION] 
                                 --m_reid M_REID 
                                 [--output_video OUTPUT_VIDEO] 
                                 [--history_file HISTORY_FILE] 
                                 [--save_detections SAVE_DETECTIONS] 
                                 [--no_show] [-d DEVICE] 
                                 [-u UTILIZATION_MONITORS] 

Multi camera multi object tracking live demo script 

optional arguments: 
  -h, --help            show this help message and exit 
  -i INPUT [INPUT ...], --input INPUT [INPUT ...]
                        Required. Input sources (indexes of cameras or paths to video files) 
  --loop                Optional.Enable reading the input in a loop 
  --config CONFIG       Configuration file 
  --detections DETECTIONS 
                        JSON file with bounding boxes 
  -m M_DETECTOR, --m_detector M_DETECTOR 
                        Path to the object detection model 
  --t_detector T_DETECTOR 
                        Threshold for the object detection model 
  --m_segmentation M_SEGMENTATION 
                        Path to the object instance segmentation model 
  --t_segmentation T_SEGMENTATION 
                        Threshold for object instance segmentation model 
  --m_reid M_REID       Required. Path to the object re-identification model 
  --output_video OUTPUT_VIDEO 
                        Optional. Path to output video 
  --history_file HISTORY_FILE 
                        Optional. Path to file in JSON format to save results of the demo 
  --save_detections SAVE_DETECTIONS 
                        Optional. Path to file in JSON format to save bounding boxes 
  --no_show 
                        Optional. Don't show output 
  -d DEVICE, --device DEVICE 
  -u UTILIZATION_MONITORS, --utilization_monitors UTILIZATION_MONITORS 
                        Optional. List of monitors to show initially.

人物追跡のデモを実行する最小限のコマンド例 (車両追跡の場合、コマンドは適切な車両検出/再識別モデルと同じです):

# ビデオ 
python multi_camera_multi_target_tracking_demo.py \ 
    -i <path_to_video>/video_1.avi <path_to_video>/video_2.avi \ 
    --m_detector <path_to_model>/person-detection-retail-0013.xml \ 
    --m_reid <path_to_model>/person-reidentification-retail-0277.xml \ 
    --config configs/person.py 

# インスタンス・セグメンテーション・モデルを使用したビデオ 
python multi_camera_multi_target_tracking_demo.py \ 
    -i <path_to_video>/video_1.avi <path_to_video>/video_2.avi \ 
    --m_segmentation <path_to_model>/instance-segmentation-security-0228.xml \ 
    --m_reid <path_to_model>/person-reidentification-retail-0277.xml \ 
    --config configs/person.py 

# ウェブカメラ 
python multi_camera_multi_target_tracking_demo.py \ 
    -i 0 1 \ --m_detector <path_to_model>/person-detection-retail-0013.xml \ 
    --m_reid <path_to_model>/person-reidentification-retail-0277.xml \ 
    --config configs/person.py

デモでは、物体検出器の代わりに検出機能を備えた JSON ファイルを使用できます。ファイルの構造は次のようになります:

[ 
    [ # Source#0 
        { 
            "frame_id": 0, 
            "boxes": [[x0, y0, x1, y1], [x0, y0, x1, y1], ...], # N bounding boxes 
            "scores": [score0, score1, ...], # N scores 
        }, 
        { 
            "frame_id": 1, 
            "boxes": [[x0, y0, x1, y1], [x0, y0, x1, y1], ...], 
            "scores": [score0, score1, ...], 
        }, 
        ...     ], 
    [ # Source#1 
        { 
            "frame_id": 0, 
            "boxes": [[x0, y0, x1, y1], [x0, y0, x1, y1], ...], # N bounding boxes 
            "scores": [score0, score1, ...], # N scores 
        }, 
        { 
            "frame_id": 1, 
            "boxes": [[x0, y0, x1, y1], [x0, y0, x1, y1], ...], 
            "scores": [score0, score1, ...], 
        }, 
        ...    ], 
    ...]

このような検出を含むファイルはデモから保存できます。引数 --save_detections を出力ファイルへのパスとともに指定します。

デモの出力#

デモでは、追跡されたオブジェクトの境界ボックスとそれらの物体の一意の ID が表示されます。デモレポート

  • FPS: ビデオフレーム処理の平均レート (1 秒あたりのフレーム数)。

  • レイテンシー: 1 フレームの処理 (フレームの読み取りから結果の表示まで) に必要な平均時間。これらのメトリックの両方を使用して、アプリケーション・レベルのパフォーマンスを測定できます。

結果とともに出力ビデオを保存するには、オプション --output_video を使用してください。構成パラメーターを変更するには、configs/person.py (車両追跡デモの場合は configs/vehicle.py) ファイルを開いて編集します。

視覚化では、次のキーを使用して制御できます:

  • space - 一時停止または次のフレーム

  • enter - ビデオを再開

  • esc - 終了

また、結果のトラックを json ファイルにダンプすることもできます。ファイルを指定するには、--history_file 引数を使用します。

品質測定#

デモでは、マルチカメラ・マルチターゲット・トラッカーの品質を測定するツールが提供されます:

  • 評価 MOT メトリック

  • 履歴ファイルからデモ結果を視覚化

MOT メトリックの評価には、py-motmetrics モジュールを使用します。評価にはグラウンド・トゥルース・アノテーション・ファイルが必要です。グラウンド・トゥルース・アノテーションでサポートされている形式は、アノテーション・ツール CVAT を介して取得できます。アノテーションには次のラベルと属性を含める必要があります:

[ 
  { 
    "name": "person", 
    "id": 0, 
    "attributes": [ 
      { 
        "id": 0, 
        "name": "id", 
        "type": "text", 
        "mutable": false, 
        "values": [ 
          " 「 
        ] 
      } 
    ] 
  } 
]

評価 MOT メトリックを実行するには、次のコマンドを使用します:

python run_evaluate.py \ 
    --history_file <path_to_file>/file.json \ 
    --gt_files \ 
      <path_to_file>/source_0.xml \ 
      <path_to_file>/source_1.xml 

グラウンド・トゥルース・ファイルの数は、使用されるビデオソースの数によって異なります。

結果を視覚化するには、次のコマンドを使用します:

python run_history_visualize.py \ 
    -i <path_to_video>/video_1.avi <path_to_video>/video_2.avi \ 
    --history_file <path_to_file>/file.json 

これは、スクリプトに設定される最小の引数です。すべての引数を表示するには、-h オプションを指定してコマンドを実行します:

usage: run_history_visualize.py [-h] [-i I [I ...]] --History_filehistory_file 
                                HISTORY_FILE [--output_video OUTPUT_VIDEO] 
                                [--gt_files GT_FILES [GT_FILES ...]]
                                [--timeline TIMELINE] [--match_gt_ids] 
                                [--merge_outputs] 

Multi camera multi target tracking visualization demo script 

optional arguments: 
  -h, --help            show this help message and exit 
  -i I [I ...]          Input videos 
  --history_file HISTORY_FILE 
                        File with tracker history 
  --output_video OUTPUT_VIDEO 
                        Output video file 
  --gt_files GT_FILES [GT_FILES ...]
                        Files with ground truth annotation 
  --timeline TIMELINE   Plot and save timeline 
  --match_gt_ids        Match GT ids to ids from history 
  --merge_outputs       Merge GT and history tracks into one frame

グラウンド・トゥルース・ファイルの形式は、MOT メトリック評価で説明したものと同じです。

プロセス分析#

デモの実行中に 2 つのオプションを使用できます:

  1. トラック一致の基準となる埋め込み間の距離を視覚化します。

  2. 埋め込みを保存して視覚化します (tensorboard 経由)。

デフォルトでは、これらのオプションは無効になっています。最初のオプションを有効にするには、構成ファイルで analyzer パラメーター enableTrue に設定してください。

2 番目のオプションでは、TensorBoard をインストールします (例えば、pip install tensorboard を使用)。次に、embeddings に対して、埋め込みに関連するデータが保存されるディレクトリーであるパラメーター save_path を指定します (空の文字列の場合、オプションは無効になります)。embeddings にはパラメーター use_images があります。True の場合、オブジェクトを含む画像はポイントではなく埋め込みごとに描画されます。

関連情報#