3
2

More than 3 years have passed since last update.

生物トラッキングのDeepLabCut動かしてみた

Posted at

はじめに

DeepLabCutとは、ディープラーニングと画像処理を使用したマーカーレスの生物トラッキングツールです。
主に、動物の行動観察に使用されています。

DeepLabCut 論文
DeepLabCut Github

今回は、Docker内でローカルで使用できるように環境構築しました。
モデルは、既存のモデルを使用して動作確認をしています。

Google Colabでの実行方法もあるので、グラウド環境が使用できる方は、そちらを使うほうが簡単です。

動作確認環境

Dockerを使用して環境を構築しました。

  • Ubuntu 18.04
  • CUDA 10.0
  • cudnn 7.6.4
  • Python 3.6.9
  • tensorflow-gpu==1.13.1

環境構築

Dockerを使用して作成しました。
元のイメージとして、OpenGLを含めたNvidiaのイメージを使用するところです。
このイメージだと、cudnnが入っていないので、予め公式ページからdebファイルをダウンロードしておきます。

Dockerfile
FROM nvidia/cudagl:10.0-devel-ubuntu18.04

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get -y upgrade &&\
    apt-get install -y git vim byobu tree wget \
    zlib1g-dev libssl-dev libffi-dev build-essential \
    checkinstall libreadline-gplv2-dev libncursesw5-dev \
    libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev \
    python3-dev python3-pip libgtk-3-dev libnotify-dev ffmpeg &&\
    rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*

RUN mkdir workspace
WORKDIR /workspace

RUN pip3 install -U pip
RUN pip3 install -U setuptools
RUN pip3 install -U -f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-18.04 wxPython
COPY libcudnn7_7.6.4.38-1+cuda10.0_amd64.deb /workspace
RUN dpkg -i libcudnn7_7.6.4.38-1+cuda10.0_amd64.deb && rm libcudnn7_7.6.4.38-1+cuda10.0_amd64.deb
RUN pip3 install tensorflow-gpu==1.13.1
RUN pip3 install deeplabcut

上のファイルとcudnnのdebファイルのある場所で、下のコマンドを実行して環境をビルドする

$ docker build . -t yourname/deeplbacut:latest

ビルドが終わったら、以下のコマンドで環境に入ります。先にホストとのデータ受け渡しフォルダを作成しておくことをおすすめします。

$ mkdir ~/docker
$ docker run -it --gpus all --net host -e DISPLAY=$DISPLAY \
-v /tmp/.X11-unix:/tmp/.X11-unix -v ~/docker:/data \
yourname/deeplbacut:latest

実行方法

Model ZooのFull_Humanを実行します。

test.py
import deeplabcut

deeplabcut.create_pretrained_project('test_project1',             # プロジェクト名
                                     'yourname',                  # 自分の名前
                                     ['/data/output_origin.avi'], # 処理にかけたい動画をリスト形式で渡す
                                     videotype='avi',             # 動画のフォーマット指定
                                     copy_videos=True)            # 元動画を処置結果のディレクトリにコピーする

実行すると、実行したディレクトリに上記で指定の[プロジェクト名]-[自分の名前]-[実行日]のディレクトリが作成されます。
ディレクトリの中身は以下。

.
├── config.yaml # 学習・認識設定ファイル
├── dlc-models # 使用したモデル
│   └── iteration-0
│       └── test_project1Jan9-trainset95shuffle1
│           ├── test
│           │   └── pose_cfg.yaml
│           └── train
│               ├── pose_cfg.yaml
│               ├── snapshot-103000.data-00000-of-00001
│               ├── snapshot-103000.index
│               ├── snapshot-103000.meta
│               ├── snapshot-103000.pb
│               └── snapshot-103000.pbtxt
├── labeled-data
│   └── output_origin
├── training-datasets
└── videos  # 出力データ
    ├── output_origin.avi
    ├── output_originDLC_resnet101_test_project1Jan9shuffle1_103000.csv
    ├── output_originDLC_resnet101_test_project1Jan9shuffle1_103000_filtered.csv
    ├── output_originDLC_resnet101_test_project1Jan9shuffle1_103000_filtered.h5
    ├── output_originDLC_resnet101_test_project1Jan9shuffle1_103000_filtered_labeled.mp4
    ├── output_originDLC_resnet101_test_project1Jan9shuffle1_103000.h5
    ├── output_originDLC_resnet101_test_project1Jan9shuffle1_103000_meta.pickle
    └── plot-poses
        └── output_origin
            ├── hist_filtered.png
            ├── plot_filtered.png
            ├── plot-likelihood_filtered.png
            └── trajectory_filtered.png

最後に

学習側を試せていないので、学習も試したいと思います(アノテーションがツライ)

3
2
1

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