安装mmsegmentation
Get started: Install and Run MMSeg
environment with PyTorch.
MMSegmentation works on Linux, Windows and macOS. It requires Python 3.7+, CUDA 10.2+ and PyTorch 1.8+.
Step 1. Create a conda environment and activate it.
conda create --name openmmlab python=3.8 -y
conda activate openmmlab
Step 2. PyTorch 环境配置
On GPU platforms: 创建环境,配置pytorch 环境(轮子提前下载到电脑上)
pip install E:\install\cuda_install\whl_cu116\torch-1.13.1+cu116-cp38-cp38-win_amd64.whl
pip install E:\install\cuda_install\whl_cu116\torchaudio-0.13.1+cu116-cp38-cp38-win_amd64.whl
pip install E:\install\cuda_install\whl_cu116\torchvision-0.14.1+cu116-cp38-cp38-win_amd64.whl
Installation
We recommend that users follow our best practices to install MMSegmentation. However, the whole process is highly customizable. See Customize Installation section for more information.
Best Practices
Step 0. Install MMCV using MIM.
pip install -U openmim
mim install mmengine
mim install "mmcv>=2.0.0"
Step 1. Install MMSegmentation.
Case a: If you develop and run mmseg directly, install it from source:
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.
这里可能遇到问题 (因为没有安装git.所以出现)
git 不是内部或外部命令,也不是可运行的程序 或批处理文件“
解决方法:下载Git https://git-scm.com/官网下载并安装
并在 电脑—>属性->高级系统设置->环境变量->系统变量->path->编辑
添加
用demo验证MMSegmentation安装是否正确
Step 1. We need to download config and checkpoint files.
mim download mmsegmentation --config pspnet_r50-d8_4xb2-40k_cityscapes-512x1024 --dest .
The downloading will take several seconds or more, depending on your network environment. When it is done, you will find two files pspnet_r50-d8_4xb2-40k_cityscapes-512x1024.py
and pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth
in your current folder.
Step 2. Verify the inference demo.
Option (a). If you install mmsegmentation from source, just run the following command.
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
第二步出现错误
AssertionError: MMCV==2.2.0 is used but incompatible. Please install mmcv>=2.0.0rc4.
原因:mmcv版本和torch以及cuda版本冲突问题导致的
解决方案:
先查看自己的troch和cuda版本:
python
import torch
print(torch.__version__)
去官网找相应的MMCV版本安装 MMCV — mmcv 2.0.0 文档
https://mmcv-zh-cn.readthedocs.io/zh_CN/2.x/get_started/installation.html
pip install mmcv==2.0.0rc3 -f https://download.openmmlab.com/mmcv/dist/cu116/torch1.13/index.html
出现错误 AssertionError: MMCV==2.0.0rc3 is used but incompatible. Please install mmcv>=2.0.0rc4.
改为
pip install mmcv==2.0.0rc4 -f https://download.openmmlab.com/mmcv/dist/cu116/torch1.13/index.html
错误 :OSError: [WinError 127] 找不到指定的程序。 Error loading "D:\Program Files\miniconda3\envs\mmseg\lib\site-packages\torch\lib\c10_cuda.dll" or one of its dependencies.
解决 :pytorch重新安装 pytorch官网 Previous PyTorch Versions | PyTorch
https://pytorch.org/get-started/previous-versions/ 安装 输入命令(梯子)
pip install torch==1.13.1+cu116 torchvision==0.14.1+cu116 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu116
不梯子得话 ,先在https://download.pytorch.org/whl/cu116 下载轮子,再本地安装
解决