• mmsegmentation V0.27.0环境搭建(一)


    1、官网

    在这里插入图片描述

    2、兼容的MMSegmentation和MMCV版本如下。请安装正确版本的MMCV,以避免安装问题。

    在这里插入图片描述

    3、Installation(Linux系统环境安装)

    1、创建虚拟环境并安装pytorch(Step 1. Create a conda environment and activate it)

    1、pytorch 与cudn的匹配版本

    pytorch 与cudn的匹配版本

    2、创建虚拟环境并安装pytorch

    conda create -n openmmseg python=3.7 -y  #创建环境
    conda activate mmdetection                  #激活环境
    conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch  #安装 PyTorch and torchvision (官方)
    
    #如果网不好,可以这样安装
    pip3 install torch==1.8.2+cu102 torchvision==0.9.2+cu102 torchaudio===0.8.2 -f https://download.pytorch.org/whl/lts/1.8/torch_lts.html  -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
    
    #验证是否安装成功
    
    >>> import torchvision
    >>> import torch
    >>> import.__version__
      File "", line 1
        import.__version__
              ^
    SyntaxError: invalid syntax
    >>> torch.__version__
    '1.8.2+cu102'
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    3、安装mmcv-full

    下面是cuda、pytorch和mmcv-full的版本
    在这里插入图片描述
    可查看cu102-torch1.8.0支持的mmcv版本号
    可查看cu102-torch1.6.0支持的mmcv版本号
    查看torch1.6.0支持的mmcv-full的版本
    注意:上面提供的预构建包不包括所有版本的mmcv-full,您可以单击相应的链接(查看torch1.6.0支持的mmcv-full的版本)来查看支持的版本。例如,您可以单击cu102-torch1.8.0,可以看到cu102-torch1.8.0只提供1.3.0及以上版本的mmcv-full。此外,从v1.3.17开始,我们不再提供使用PyTorch 1.3和1.4编译的完整的mmcv预构建包。你可以在这里找到用PyTorch 1.3和1.4编译的以前版本。在我们的Cl中,兼容性仍然得到保证,但我们将在明年放弃对PyTorch 1.3和1.4的支持
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    注意:上面提供的预构建包不包括所有版本的mmcv-full,您可以单击相应的链接来查看支持的版本。例如,您可以单击cu102-torch1.8.0,可以看到cu102-torch1.8.0只提供1.3.0及以上版本的mmcv-full。此外,从v1.3.17开始,我们不再提供使用PyTorch 1.3 & 1.4编译的完整mmcv预构建包。您可以在这里找到使用PyTorch 1.3和1.4编译的以前版本。在我们的Cl中仍然确保了兼容性,但我们将在明年放弃对PyTorch 1.3和1.4的支持。

    #Install mmcv-full. 安装mmcv-full
    pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/{cu_version}/{torch_version}/index.html
    
    Please replace {cu_version} and {torch_version} in the url to your desired one. For example, to install the latest mmcv-full with CUDA 11.0 and PyTorch 1.7.0, use the following command:
    
    #案例1:(安装最新版本)
    pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu110/torch1.7.0/index.html
    pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu102/torch1.8.0/index.html
    
    #案例2:(安装特定版本)
    pip install mmcv-full==1.3.13 -f https://download.openmmlab.com/mmcv/dist/cu111/torch1.9.0/index.html #明确mmcv-full的版本号
    
    pip install mmcv-full==1.4.4 -f https://download.openmmlab.com/mmcv/dist/cu102/torch1.8.0/index.html -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com #(镜像加速安装最新版本)
    
    pip install mmcv-full==1.6.0 -f https://download.openmmlab.com/mmcv/dist/cu102/torch1.8.0/index.html -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
    
    
    #验证是否安装成功
    import mmcv
    
    #如果出现
    >>> import mmcv
    No CUDA runtime is found, using CUDA_HOME='/usr/local/cuda-10.2'
    
    #我们去看看驱动:
    nvidia-smi
    
    如果返回NVIDIA驱动失效简单解决方案:NVIDIA-SMI has failed because it couldn‘t communicate with the NVIDIA driver.
    
    这种情况是由于重启服务器,linux内核升级导致的,由于linux内核升级,之前的Nvidia驱动就不匹配连接了,但是此时Nvidia驱动还在,可以通过命令 nvcc -V 找到答案。
    
    
    
    #解决方法:
    查看已安装驱动的版本信息
    ls /usr/src | grep nvidia
    (mmdetection) lhy@thales-Super-Server:~$ ls /usr/src | grep nvidia
    nvidia-440.33.01
    
    
    #进行下列操作
    sudo apt-get install dkms
    sudo dkms install -m nvidia -v 440.33.01
    
    
    #然后进行验证:
    (mmdetection) lhy@thales-Super-Server:~$ nvidia-smi
    Fri May  6 00:56:02 2022       
    +-----------------------------------------------------------------------------+
    | NVIDIA-SMI 440.33.01    Driver Version: 440.33.01    CUDA Version: 10.2     |
    |-------------------------------+----------------------+----------------------+
    | GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
    | Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
    |===============================+======================+======================|
    |   0  TITAN RTX           Off  | 00000000:02:00.0 Off |                  N/A |
    |  0%   47C    P0    54W / 280W |      0MiB / 24220MiB |      0%      Default |
    +-------------------------------+----------------------+----------------------+
    |   1  TITAN RTX           Off  | 00000000:03:00.0 Off |                  N/A |
    |  0%   47C    P0    65W / 280W |      0MiB / 24220MiB |      0%      Default |
    +-------------------------------+----------------------+----------------------+
    |   2  TITAN RTX           Off  | 00000000:82:00.0 Off |                  N/A |
    |  0%   48C    P0    63W / 280W |      0MiB / 24220MiB |      1%      Default |
    +-------------------------------+----------------------+----------------------+
    |   3  TITAN RTX           Off  | 00000000:83:00.0 Off |                  N/A |
    |  0%   46C    P0    42W / 280W |      0MiB / 24220MiB |      0%      Default |
    +-------------------------------+----------------------+----------------------+
                                                                                   
    +-----------------------------------------------------------------------------+
    | Processes:                                                       GPU Memory |
    |  GPU       PID   Type   Process name                             Usage      |
    |=============================================================================|
    |  No running processes found                                                 |
    +-----------------------------------------------------------------------------+
    (mmdetection) lhy@thales-Super-Server:~$ python
    Python 3.7.13 (default, Mar 29 2022, 02:18:16) 
    [GCC 7.5.0] :: Anaconda, Inc. on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import mmcv
    >>> mmcv.__version__
    '1.4.4'
    
    
    • 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
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81

    4、MMSegmention安装

    在这里插入图片描述

    git clone https://github.com/open-mmlab/mmsegmentation.git
    cd mmsegmentation
    
    安装构建要求,然后安装mmdetection。(我们通过github repo安装pycocotools而不是pypi,因为pypi版本较旧并且与最新的numpy不兼容。)
    pip install cython  -i http://mirrors.aliyun.com/pypi/simple/  --trusted-host mirrors.aliyun.com 
    pip install -r requirements.txt -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
    
    
    pip install "git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI"
    如果网不好,可以按照下面的步骤安装
    git clone https://github.com/cocodataset/cocoapi.git
    cd cocoapi/PythonAPI
    python setup.py build_ext --inplace
    python setup.py build_ext install
    
    
    pip install -e .  # or "python setup.py develop"
    Using /home/lhy/anaconda3/envs/mmsegmention/lib/python3.7/site-packages
    Finished processing dependencies for mmsegmentation==0.24.1
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    在这里插入图片描述

    4、 测试环境搭建成功

    python demo/image_demo.py demo/demo.png  configs/swin/upernet_swin_tiny_patch4_window7_512x512_160k_ade20k.py  upernet_swin_tiny_patch4_window7_512x512.pth --palette ade
    
    • 1

    在这里插入图片描述

    5、安装其他库

    linux chown命令解除文件夹的root权限限制

    sudo chown -R demouser file
    
    • 1

    这个命令可以解除linux文件的超级权限限制

    1、安装gdal

    添加源

    sudo add-apt-repository ppa:ubuntugis && sudo apt update
    
    • 1
    conda install gdal
    
    • 1

    验证库安装成功

    >>> from osgeo import gdal
    >>> from osgeo import ogr
    >>> from osgeo import osr
    
    
    • 1
    • 2
    • 3
    • 4

    2、安装scikit-image

    pip install scikit-image -i https://pypi.tuna.tsinghua.edu.cn/simple
    
    • 1

    3、安装fiona和rasterio

    pip install fiona -i https://pypi.tuna.tsinghua.edu.cn/simple
    pip install rasterio -i https://pypi.tuna.tsinghua.edu.cn/simple
    
    • 1
    • 2

    4、安装albumentations

    pip install albumentations -i https://pypi.tuna.tsinghua.edu.cn/simple
    
    • 1
  • 相关阅读:
    树莓派 ubuntu18.04安装ROS
    数据守护集群之MPP主备集群
    Java发展历史
    R语言数学建模(三)—— 模型工作流
    【Ascend C算子开发(入门)】——Ascend C编程模式与范式
    vue2设置首页和个人信息页
    【LeetCode】1282. 用户分组
    未来软件测试行业职业选择有哪些?
    【旅游网】前后端分离——用户管理
    《征服数据结构》栈
  • 原文地址:https://blog.csdn.net/qq_41627642/article/details/126452006