1
1

MMdetectionの環境構築

Last updated at Posted at 2024-05-15

公式の通りではうまくいかなかったので記録

環境

Windows11
RTX 3060Ti
CUDA11.8

公式を見ながらインストール開始

仮想環境作成

コマンドプロンプトを起動して
Python3.8で仮想環境作成

conda create --name openmmlab python=3.8 -y
conda activate openmmlab

torchインストール

conda install pytorch torchvision -c pytorch

↑このコマンドに不安を覚えつつ実行

確認してみる

python
>>> import torch
>>> torch.cuda.is_available()
False

やはりダメ

torchのversionを確認

>>> torch.__version__
'1.13.1

結構古め

なので
https://pytorch.org/get-started/previous-versions/
previous versionを参考に以下を実行

conda install pytorch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 pytorch-cuda=11.7 -c pytorch -c nvidia

確認してみる

python
>>> import torch
>>> torch.cuda.is_available()
False

またしてもダメ

3度目の正直

pip install torch==1.13.1+cu117 torchvision==0.14.1+cu117 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu117

確認してみる

python
>>> import torch
>>> torch.cuda.is_available()
True

いけました!

PCのCUDAのversionは11.8なのですがtorch1.13.1はcuda11.7までしか対応していない模様…

mmengineとmmcvインストール

pip install -U openmim
mim install mmengine

公式ではこのあと
mim install "mmcv>=2.0.0"
ですが…
エラーが出ます
AssertionError: MMCV==2.2.0 is used but incompatible. Please install mmcv>=2.0.0rc4, <2.2.0.

↓バージョンが気に食わないそうなのでこちらを実行

mim install "mmcv<2.2.0" 

mmdetectionインストール

git clone https://github.com/open-mmlab/mmdetection.git
cd mmdetection
pip install -v -e .

確認をば

python
>>> import mmdet

エラーが出なければOK

インストール確認

jupyter labをインストール

  • rtmdet_tiny_8xb32-300e_coco.py
  • rtmdet_tiny_8xb32-300e_coco_20220902_112414-78e30dcc.pth
    をダウンロードするため以下のコマンドを実行
mim download mmdet --config rtmdet_tiny_8xb32-300e_coco --dest .

以下のコードで実行確認

check.py
from mmdet.apis import init_detector, inference_detector

config_file = 'rtmdet_tiny_8xb32-300e_coco.py'
checkpoint_file = 'rtmdet_tiny_8xb32-300e_coco_20220902_112414-78e30dcc.pth'
model = init_detector(config_file, checkpoint_file, device='cuda')  # or device='cuda:0'
inference_detector(model, 'demo/demo.jpg')

※CUDAは11.8のままでも動く模様

完了!!

1
1
0

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
1
1