Deep-Architecture Blog

ディープラーニング勉強中の建築学生のブログです.

動画アノテーションツール VATIC(Video Annotation Tool from Irvine, California)を簡単にインストールする方法

VATIC(Video Annotation Tool from Irvine, California)という動画アノテーションツールを簡単にインストールする方法と使い方を紹介します.

VATICとは?

VATIC(Video Annotation Tool from Irvine, California)はコンピュータビジョン研究のための無料でオープンソースの動画注釈ツールです。
公式サイト:vatic - Video Annotation Tool - UC Irvine

VATICを使えば,何フレーム目にオブジェクトがどの枠内にいたかの要素(フレーム番号,タグ名,座標)の一覧を作成することができます.

応用すれば,このような動画も作ることができるそうです. www.youtube.com

何に使うの?

用途としては,ディープラーニングによる動画の一般物体検出アルゴリズムの教師データ作成などが挙げられます.一般物体検出アルゴリズムの例としてはFast R-CNN, YOLO(You Only Look Once), SSD(Single Shot MultiBox Detector)などがあります.
動画の教師データを1フレームごとに手作業で作成するのは非常に手間であるため,VATICを使うのはとても意義のあることだと考えられます.

なぜこの記事を書いたか?

何よりもVATICのインストール方法が書かれた記事が少なかったことが理由の1つです.また,普通にインストールしようとすると環境構築をするのに非常に手間と時間がかかってしまうが,英語のブログで簡単にVATICをインストールできる方法を見つけたので日本語でまとめようと思いました.
参考としてVATICの通常のインストール方法が書かれている記事です.
qiita.com

簡単なVATICのインストール方法

自分の環境 : Ubuntu 16.04 (Windows10 VirtualBox上)
参考にさせて頂いたサイトはこちら:

glentimemaker.github.io github.com

Step 1. Dockerをインストール

Dockerというコンテナ型のアプリケーション実行環境をインストールします.
すでにインストールされている方は飛ばしてください.
私はDocker CEをインストールしました.
インストール方法 : Redirecting…

Step 2. フォルダ,テキストファイル,動画ファイルを用意

  1. 作業を行いたい場所に"data"という名前のフォルダを作成します.
  2. "data"フォルダ内に “labels.txt”というテキストデータを作成します.
    “labels.txt”の1行目に使用したいタグを追加します.タグ同士は半角スペースで区切ってください.
    例:people car dog cat
  3. "data"フォルダ内に "videos_in"という名前のフォルダを作成し,その中に動画ファイルを用意してください.動画の拡張子は"avi"か"mp4"が望ましいです.

Step 3. コンテナ作成

コマンドプロンプトで"data"フォルダがあるディレクトリまで移動し,以下のコマンドを実行してください.
$ sudo docker run -it -p 8111:80 -v $PWD/data:/root/vatic/data npsvisionlab/vatic-docker
8111はポート番号です.数字は自由に変えても構いません.
実行すると自動的にDockerコンテナのbashにアクセスします.

Step 4. 設定ファイル書き換え

既存の設定だと約300フレーム(約8秒)ごとに動画が区切られてしまうため,設定ファイルの書き換えを行います.
以下の操作はコンテナのbashで行います.

まず,# vi ./root/vatic/example.shを実行し設定ファイルの書き換えを行ってください.設定に関する変数はTURKOPSです.
例えば,
TURKOPS="--offline --title HelloTurk!"

TURKOPS="--offline --title HelloTurk! --length 10000"
に変更すると10000フレームまとめてアノテーションを行うことができるようになります.

保存して終了したら, # sh ./root/vatic/example.sh を実行すれば,アノテーションを行うための準備が完了します.

補足として,設定の一覧を以下に示します.

MTurk Options
    --title         The title that MTurk workers see
    --description   The description that MTurk workers see
    --duration      Time in seconds that a worker has to complete the task
    --lifetime      Time in seconds that the task is online
    --keywords      Keywords that MTurk workers can search on
    --offline       Disable MTurk and use for self annotation only

Compensation Options
    --cost                  The price advertised to MTurk workers
    --per-object-bonus      A bonus in dollars paid for each object
    --completion-bonus      A bonus in dollars paid for completing the task

Qualification Options
    --min-approved-percent  Minimum percent of tasks the worker must have
                            approved before they can work for you
    --min-approved-amount   Minimum number of tasks that the worker must
                            have completed before they can work for you

Video Options
    --length        The length of each segment for this video in frames
    --overlap       The overlap between segments in frames
    --use-frames    When splitting into segments, only the frame intervals
                    specified in this file. Each line should contain a
                    start frame, followed by a space, then the stop frame.
                    Frames outside the intervals in this file will be
                    ignored.
    --skip          If specified, request annotations only every N frames.
    --blow-radius   When a user marks an annotation, blow away all other
                    annotations within this many frames. If you want to
                    allow the user to make fine-grained annotations, set
                    this number to a small integer, or 0 to disable. By
                    default, this is 5, which we recommend.

Step 6. アノテーション

ブラウザを開き,
localhost:8111/directory

にアクセスします.(ポート番号が8111の時)
"Video Segment"をクリックすることでアノテーションを開始することができます. 使い方は本家の動画がわかりやすいです.

www.youtube.com

Step 7. 出力

アノテーションが完了したら右下にある"Save Work"をクリックし作業を保存します.その後,トップページに戻り"Output Labels"をクリックします.
"Dumping video currentvideo"というメッセージが出れば成功です.
"data"フォルダに"output.xml"というデータが出力されているはずです.
このように出力されます.

<annotation>
    <folder>mylabels</folder>
    <filename>currentvideo.flv</filename>
    <source><type>video</type><sourceImage>vatic frames</sourceImage>
    <sourceAnnotation>vatic</sourceAnnotation></source>

    <object>
        <name>people</name>
        <moving>true</moving>
        <action/>
        <verified>0</verified>
        <id>0</id>
        <createdFrame>0</createdFrame>
        <startFrame>0</startFrame>
        <endFrame>999</endFrame>
        <polygon>
            <t>0</t>
            <pt><x>33</x><y>43</y><l>1</l></pt>
            <pt><x>33</x><y>113</y><l>1</l></pt>
            <pt><x>111</x><y>113</y><l>1</l></pt>
            <pt><x>111</x><y>43</y><l>1</l></pt>
        </polygon>

        .
        .
        .

        <polygon>
        <t>999</t>
            <pt><x>33</x><y>43</y><l>1</l></pt>
            <pt><x>33</x><y>113</y><l>1</l></pt>
            <pt><x>111</x><y>113</y><l>1</l></pt>
            <pt><x>111</x><y>43</y><l>1</l></pt>
        </polygon>
    </object>
</annotation>

Step 8. 終了方法

コンテナのbash上で# exitを実行すると,ローカルに戻ってくることができます.
その後,$ sudo docker ps -aを実行すると以下のような結果が出力されるので,CONTAINER IDを確認してください.

CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS              PORTS                           NAMES
xxxxxxxxxxxx        npsvisionlab/vatic-docker   "/bin/bash -C /roo..."   8 hours ago         Up 20 minutes       443/tcp, 0.0.0.0:8111->80/tcp   wonderful_elion

CONTAINER ID(この場合,xxxxxxxxxxxx)を確認したら,コマンドプロンプト$ sudo docker stop xxxxxxxxxxxxを実行すれば安全に終了することができます.

Step 9. 後日作業を続ける時

$ sudo docker start xxxxxxxxxxxxを実行した後,Step 4と同じようにlocalhost:8111/directoryにアクセスしてください.

以上,VATICのインストール方法でした.
アノテーションデータはxlm形式であるため,実際にPythonなどで実装するときの詳しい方法などは後日まとめようと思います.