devcon-mmdet3d

This text is also text!

ファイルの準備


Dockerfileの作成


Modify Dockerfile as follow.

[Dockerfile]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
FROM nvidia/cuda:11.3.1-cudnn8-devel-ubuntu20.04

ENV DEBIAN_FRONTEND=noninteractive

# Install some basic utilities
RUN apt-get update && apt-get install wget -yq
RUN apt-get install build-essential g++ gcc -y
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get install libgl1-mesa-glx libglib2.0-0 -y
RUN apt-get install openmpi-bin openmpi-common libopenmpi-dev libgtk2.0-dev git -y

# Install conda
ENV CONDA_DIR /opt/conda
RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-py38_23.11.0-1-Linux-x86_64.sh -O ~/miniconda.sh && \
/bin/bash ~/miniconda.sh -b -p /opt/conda

ENV PATH=$CONDA_DIR/bin:$PATH
RUN conda install python=3.8

### Install pytorch
RUN pip install torch==1.9.1+cu111 torchvision==0.10.1+cu111 torchaudio==0.9.1 -f https://download.pytorch.org/whl/torch_stable.html

### Pip install mmcv-full in conda
RUN /opt/conda/bin/pip install mmcv-full==1.4.0 -f https://download.openmmlab.com/mmcv/dist/cu111/torch1.9.0/index.html

RUN /opt/conda/bin/pip install mmdet==2.14.0 \
mmsegmentation==0.14.1 \
timm \
Pillow==8.4.0 \
tqdm \
torchpack \
mpi4py==3.0.3 \
numba==0.48.0 \
nuscenes-devkit==1.1.9

RUN conda install conda-build pyyaml numpy ipython cython typing typing_extensions mkl mkl-include ninja &&\
/opt/conda/bin/conda clean -ya

WORKDIR /root/workspace

devcontainer.jsonの作成

Modify devcontainer.json as follow.

[devcontainer.json]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
{
"name": "bev-playground",
"build": {
"dockerfile": "Dockerfile",
"context": ".."
},
"remoteUser": "root",
"workspaceFolder": "/workspace",
"remoteEnv": {
"TRT_LIBPATH": "/usr/lib/x86_64-linux-gnu",
"TRT_OSSPATH": "/workspace/TensorRT"
},
"runArgs": [
"--gpus",
"all",
"--shm-size",
"16gb"
],
"mounts": [
"source=${localWorkspaceFolder},target=/workspace,type=bind",
"source=${localWorkspaceFolder}/dataset/can_bus,target=/workspace/VAD/data/can_bus,type=bind",
"source=${localWorkspaceFolder}/dataset/nuscenes,target=/workspace/VAD/data/nuscenes,type=bind",
],
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance"
],
"settings": {
"python.defaultInterpreterPath": "/opt/conda/bin/python3"
}
}

Dockerビルド


VscodeでReopen containerをクリックして、コンテナをビルドし始めます。

mmdet3dインストール


コンテナでは、mmdet3dをインストールします。

[Dockerfile]
1
2
3
4
  git clone https://github.com/open-mmlab/mmdetection3d.git &&\
cd mmdetection3d &&\
git checkout -f v0.17.1 &&\
python setup.py develop

Troubleshooting


mmdet3dをインストールするとき、libやlibのバージョンが合わせない問題が発生しました。(更新予定)
以下のように修正してください。

1
2
3
4
5
6
7
scikit-image==0.21.0
networkx==3.1
pandas==2.0.3
numba==0.48.0
numpy==1.21.1
similaritymeasures==1.2.0
shaplely==1.8.5

vscode-devcon-1

This text is also text!

必要なツールのインストール


  • VSCode: 公式サイトからインストール
  • Docker Desktop: 公式サイトからインストール
  • VSCode拡張機能

プロジェクト構造の準備


1
2
3
4
5
6
7
project/
├── .devcontainer/
│ ├── devcontainer.json
│ ├── Dockerfile
├── src/
│ └── main.py
└── requirements.txt

各ファイルの作成


Dockerfileの作成

まず、Dockerfileを作成します。Docker imagesがビルドされます。

[dockerfile]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Dockerfile
FROM python:3.10-slim

# 必要なツールをインストール
RUN apt-get update && apt-get install -y \
curl \
git \
&& rm -rf /var/lib/apt/lists/*

# ワークスペースを設定
WORKDIR /workspace

# Python環境をセットアップ
COPY requirements.txt /workspace/
RUN pip install --no-cache-dir -r requirements.txt

devcontainer.jsonの作成

次に、devcontainerからdockerイメージをビルドし、Containerを起動するためdevcontainer.jsonで設定します。

マウント設定もここで設定します。

1
2
3
"mounts": [
"source=${localWorkspaceFolder},target=/workspace,type=bind"
]
[devcontainer.json]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// .devcontainer/devcontainer.json
{
"name": "Python DevContainer",
"build": {
"dockerfile": "Dockerfile",
"context": ".."
},
"settings": {
"python.pythonPath": "/usr/local/bin/python"
},
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance"
],
"forwardPorts": [8000],
"postCreateCommand": "pip install --no-cache-dir -r requirements.txt",
"remoteUser": "root",
"workspaceFolder": "/workspace",
"mounts": [
"source=${localWorkspaceFolder},target=/workspace,type=bind"
]
}

launch.jsonの作成

Debuggerを使ってデバックするためlaunch.jsonを作成します。

[launch.json]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// .vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Docker Debug",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/src/main.py",
"console": "integratedTerminal",
"justMyCode": true
}
]
}

その他のファイルの作成

requirements.txtの作成

[requirements.txt]
1
2
3
4
5
requests==2.31.0      # HTTPリクエストを送信するためのライブラリ
numpy==1.26.0 # 数値計算ライブラリ
pandas==2.1.1 # データ分析ライブラリ
scipy==1.11.3 # 科学技術計算ライブラリ
matplotlib==3.8.0 # グラフ描画ライブラリ

src/main.pyの作成

今回デバックしたいpythonファイルを作成します。

まとめ


以上、Vscode + Devcontainerのdocker containerの中でデバック環境を構築することができました。
必要なLibについて、Dockerfilerequirements.txtを追加・修正してカスタマイズしてください。