安装:
Step 1:创建Conda 环境并激活之
conda create --name openmmlab python=3.8 -y
conda activate openmmlab
Step 2:CUDA版本选择,及安装Pytorch
关于设备GPU的cuda版本,根据如下的选择原则:
- 对于Ampere架构的NVIDIA的GPU,例如GeForce 30系列核NVIDIA A100,必须安装CUDA11。
- 对于旧版的NVIDIA GPUS,CUDA 11 是向下兼容的,但是 CUDA10.2会更轻量化并且表现更好的性能
确定好cuda版本后,进入Torch官网选择对应版本的Pytorch进行安装
pip install -U openmim
mim install mmengine
mim install "mmcv>=2.0.0"
Step 4:安装 MMSegmentation.
git clone -b main https://github.com/open-mmlab/mmsegmentation.git
cd mmsegmentation
pip install -v -e .
# '-v' means verbose, or more output
# '-e' means installing a project in editable mode,
# thus any local modifications made to the code will take effect without reinstallation.
验证:
Step 1. We need to download config and checkpoint files.下载config和checkpoint 文件
mim download mmsegmentation --config pspnet_r50-d8_4xb2-40k_cityscapes-512x1024 --dest .
Step 2. Verify the inference demo.验证推理demo
Option (a). If you install mmsegmentation from source, just run the following command.
方式(a)如果你从源码安装mmsegmentation,只需要运行下面的命令
python demo/image_demo.py demo/demo.png configs/pspnet/pspnet_r50-d8_4xb2-40k_cityscapes-512x1024.py pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth --device cuda:0 --out-file result.jpg
You will see a new image result.jpg
on your current folder, where segmentation masks are covered on all objects.
你如果看到了一个新图片result.jpg在你当前文件夹,说明安装成功了。(运行时,可能会有一些warning,但不影响结果的生成)