はじめに
DebianでSingularityを使ってDeepLabCutの環境構築を行ったときのメモです。
Anaconda3で環境を作りましたが汎用性に欠けるので、Singularityでも計算できるようにしました。
注意点
ホストとSingularityイメージで使うNVIDIAドライバのバージョンは揃える必要があります。
ホストNVIDIAドライバが525の場合は、Singularityイメージは520以上のものを選択します。
520、530、550くらいで揃えた方が良いです。
CUDAのバージョンなどは揃える必要があります。
環境
- Debian 12 bookworm - Singularity-ce 4.0.1 - DeepLabCut 2.3.9 - nvidia-driver 525.147.05-4~deb12u1 - nvidia-cuda-dev 11.8.89~11.8.0-5~deb12u1 - nvidia-cuda-toolkit 11.8.89~11.8.0-5~deb12u1 - nvidia-cudnn 8.5.0.96~cuda11.7
GPU関連ライブラリのインストール
ホストであるDebianにインストールします。
当サイトでは以下をご参照ください。

Singularityのインストール
当サイトでは以下をご参照ください。
Ubuntuの場合はパッケージがあります。

SingularityのDefinition Files
SingularityのDefinition Filesを作成します。
元となるDockerイメージはDocker Hubにある「nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04」です。
ホスト(Debian)にインストールしたCUDAなどのバージョンに合わせて選択します。
numpyとsphinxはTensorFlowのバージョンに合わせるため、最後にバージョンを指定してインストールしています。
deeplabcut.extract_frames関数で抽出したフレームが、deeplabcut.label_frames関数を実行してGUI起動したときに選択されていない不具合がありました。
メニューの「File」→「Open Folder」で「プロジェクト名-氏名-実行日時/labeled-data/動画ファイル名」のディレクトリを指定すれば良いです。
Bootstrap: docker
From: nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04
%labels
Author: tama 20240423
%environment
export LC_ALL=C
alias ll='ls -la'
%post
apt update
export DEBIAN_FRONTEND=noninteractive
apt install -y --no-install-recommends \
python3.10 \
python3-pip \
python3-dev \
python3-wxgtk4.0 \
ffmpeg \
build-essential \
make \
cmake \
gcc \
g++ \
locales \
git \
wget \
lv \
libgtk-3-dev \
libsm6 \
libxext6 \
libxdamage1 \
libglib2.0-0 \
libgl1-mesa-dev \
libdbus-1-3 \
libfontconfig1 \
libxkbcommon-x11-0 \
libxcb-icccm4 \
libxcb-image0 \
libxcb-keysyms1 \
libxcb-randr0 \
libxcb-render-util0 \
libxcb-shape0 \
libcanberra-gtk-module \
libxrender1 \
libgstreamer-plugins-base1.0-dev \
libxkbcommon-x11-0 \
libxcb-shape0 \
libxcb-render-util0 \
libxcb-keysyms1 \
libxcb-image0 \
libxcb-icccm4 \
libcanberra-gtk-module
apt autoremove -y
apt clean
rm -rf /var/lib/apt/lists/*
locale-gen en_US.UTF-8 en_GB.UTF-8
pip uninstall -y Pillow
pip uninstall -y opencv-python opencv-python-headless
pip install --no-cache-dir opencv-python-headless
pip install --no-cache-dir wxPython
pip install --no-cache-dir deeplabcut[gui,tf]
pip install --upgrade sphinx==4.3
pip install --upgrade numpy==1.23
Singularityのイメージ作成と実行
作業ディレクトリに移動して、コマンドを実行します。
Definition Files「DeepLabCut-2024xxxx.def」は、作業ディレクトリに置きます。
イメージ作成にはsudo権限が必要です。
cd 作業ディレクトリ sudo singularity build DeepLabCut-2024xxxx.sif DeepLabCut-2024xxxx.def
実行します。
singularity run --nv DeepLabCut-20240423.sif
TensorFlowからGPUが認識できることを確認します。
ipythonでシェルに入り、コマンドを実行して「True」が表示されたら良いです。
ipython import tensorflow as tf tf.test.is_gpu_available()
DeepLabCutの実行
ipythonに入ってDeepLabCutをインポートした後の手順は、当サイトでは下記をご参照ください。

ipython import deeplabcut


Comments