安装 cuda

  • 查看 nvidia 最高支持多少版本的 cuda
nvidia-smi.exe

+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 560.94                 Driver Version: 560.94         CUDA Version: 12.6     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                  Driver-Model | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GeForce RTX 4060 Ti   WDDM  |   00000000:01:00.0  On |                  N/A |
| 30%   30C    P8              4W /  160W |     654MiB /   8188MiB |      2%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

安装 Miniconda

这样随便一个 cmd 都能执行 conda 命令了

创建并使用 conda 环境

// 创建
conda create --name openmmlab python=3.9 -y
// 使用
conda activate openmmlab


// 退出
conda deactivate 
// 删除 
conda remove --name your_env_name --all

安装 pytorch

根据安装的 cuda 版本、系统环境、语言环境在 https://pytorch.org/get-started/locally/ 选择最佳的安装版本。我的是 cuda 12.6 、Window11、conda所以使用下面的命令

// Latest PyTorch requires Python 3.9 or later. 最新版PyTorch需要Python 3.9或更高版本。

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126

MMDetection 开始

  • 使用 openmim 来管理 MMEngine 和 MMCV。
pip install -U openmim
mim install mmengine
// 这里我自己加上了 <=2.1.0 不然官网项目起不来
mim install "mmcv>=2.0.0, <=2.1.0"
  • 下载 github 上的项目
git clone https://github.com/open-mmlab/mmdetection.git

cd mmdetection

pip install -v -e .
  • 下载配置文件和模型权重文件。
mim download mmdet --config rtmdet_tiny_8xb32-300e_coco --dest .
  • 测试项目
python demo/image_demo.py demo/demo.jpg rtmdet_tiny_8xb32-300e_coco.py --weights rtmdet_tiny_8xb32-300e_coco_20220902_112414-78e30dcc.pth [--device cpu]

报错

  • PyTorch 2.6,weights\_only\=True
        (1) In PyTorch 2.6, we changed the default value of the `weights_only` argument in `torch.load` from `False` to `True`. Re-running `torch.load` with `weights_only` set to `False` will likely succeed, but it can result in arbitrary code execution. Do it only if you got the file from a trusted source.
        (2) Alternatively, to load with `weights_only=True` please check the recommended steps in the following error message.

修改 C:\ProgramData\miniconda3\envs\openmmlab\lib\site-packages\mmengine\runner\checkpoint.py 中的

checkpoint = torch.load(filename, map_location=map_location)

checkpoint = torch.load(filename, map_location=map_location, weights_only=False)

摄像头识别

  • 下载 faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth
http://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth
  • 识别
python demo/webcam_demo.py configs/faster_rcnn/faster-rcnn_r50_fpn_1x_coco.py checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth

标签: windows, MMDetection

添加新评论