Windows10下安装detectron2超详细教程(小白视角)

前言

在查了半天的资料,踩了无数的坑后,我来给大家总结下windows10下安装detectron2的超详细教程(最终亲测成功)。关于anaconda3与pytorch安装百度很多了,这里就不介绍了。

NVIDIA显卡驱动

这里官方文档介绍采用CUDA10.1(其他旧版本驱动未测试)。
因此如果目前cuda的版本不是10.1或10.1以上,就卸载掉,然后安装cuda10.1。
cuda10.1完成以后,新增系统环境变量:

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\libnvvp
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\lib\x64

安装vs2019

1)detectron2需要vs2019最新的编译器,安装vs2019的社区/专业/企业版本均可,因为社区版较为简单,因此这里以社区版为例。
下载地址:https://visualstudio.microsoft.com/zh-hans/vs/ 点击跳转.
2)detectron2需要vs2019当中的cl.exe,因此你需要配置cl.exe的系统环境

参照我的:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\bin\Hostx64\x64
注意记住这里的版本号14.27,后面用到,每个人可能不一样

配置好系统环境后请务必保证在打开cmd输入cl显示如下内容:
在这里插入图片描述
3)如果之前电脑上已经装了vs的其他版本,重新设置vs2019的编译器,操作如下:
SET MSSdk=1
SET DISTUTILS_USE_SDK=1
call “C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat” amd64 -vcvars_ver=14.27
每个人的vcvarsall.bat路径和版本不一样,找到自己的路径和版本,然后替换掉上面的。
操作完毕显示内容如下:
在这里插入图片描述

安装cocoapi(windows)

下载以下链接的cocoapi,因为cocoapi官方暂不支持Windows
https://github.com/philferriere/cocoapi 点击跳转.
然后用以下指令安装
cd coco/PythonAPI
python setup.py build_ext --inplace
python setup.py build_ext install

如果报cl: 命令行 error D8021 :无效的数值参数“/Wno-cpp” 和 cl: 命令行 error D8021 :无效的数值参数“/Wno-unused-function”,则打开setup.py,删除如下参数

在这里插入图片描述

打开cmd输入
import pycocotools;
from pycocotools.coco import COCO
没报错即成功

在这里插入图片描述

安装fvcore:

下载链接:https://github.com/facebookresearch/fvcore 点击跳转.
然后cd到setup.py所在目录,用以下指令安装
python setup.py build --force develop
打开cmd输入 import fvcore 没报错即成功

安装detectron2

在安装detectron2前需要先修改detectron2与pytorch的代码以保证顺利安装。
下载地址:https://github.com/conansherry/detectron2 点击跳转.
1)根据官方文档对pytorch进行如下修改(觉得难找可以下载Everything)

file1:
{your evn path}\Lib\site-packages\torch\include\torch\csrc\jit\argument_spec.h
example:
{C:\Miniconda3\envs\py36}\Lib\site-packages\torch\include\torch\csrc\jit\argument_spec.h(190)
   static constexpr size_t DEPTH_LIMIT = 128;
      change to -->
   static const size_t DEPTH_LIMIT = 128;
file2:
{your evn path}\Lib\site-packages\torch\include\pybind11\cast.h
example:
{C:\Miniconda3\envs\py36}\Lib\site-packages\torch\include\pybind11\cast.h(1449)
    explicit operator type&() { return *(this->value); }
      change to -->
   explicit operator type&() { return ((type)this->value); }

第一个文件的位置有变动为:{your evn path}\Lib\site-packages\torch\include\torch\csrc\jit\runtime\argumenta_spec.h

2)将detectron2\detectron2\layers\csrc\deformable 文件夹下三个文件中全部的 AT_CHECK 全部替换为 TORCH_CHECK

3)安装detectron2

//进入解压后setup.py的路径
cd detectron2
//安装
python setup.py build --force develop

安装成功显示如下:
在这里插入图片描述
pip list查看结果

在这里插入图片描述
最后来总结一些坑,以及坑产生的原因与解决方案

错误产生原因以及解决方案

1)执行call “C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat” amd64 -vcvars_ver=14.24后,报如下错误

在这里插入图片描述
产生原因:amd64 -vcvars_ver=14.24 版本不一致,我的是14.27。
解决方案:查看自身版本
在这里插入图片描述

  1. 在执行python setup.py build --force develop后,报如下错误

error: command ‘C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\bin\HostX86\x64\cl.exe’ failed with exit status 2

产生原因:存在多版本vs,未设置vs2019的编译器。
解决方案:

SET MSSdk=1
SET DISTUTILS_USE_SDK=1
call “C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat” amd64 -vcvars_ver=14.27

3)在执行python setup.py build --force develop后,报如下错误
在这里插入图片描述解决方案:

将detectron2\detectron2\layers\csrc\deformable 文件夹下三个文件中全部的 AT_CHECK 全部替换为 TORCH_CHECK

4)如果遇到编码错误问题请参照以下解决方案(本人暂未遇到)
打开你环境下的cpp_extension.py, 找到如下代码段的位置,在decode() 的括号中添加 ’ gbk’ (注意gbk前面有空格)

if sys.platform.startswith('darwin'):
        # There is no particular minimum version we need for clang, so we're good here.
        return True
    try:
        if sys.platform.startswith('linux'):
            minimum_required_version = MINIMUM_GCC_VERSION
            version = subprocess.check_output([compiler, '-dumpfullversion', '-dumpversion'])
            //修改处1
            version = version.decode(' gbk').strip().split('.')
        else:
            minimum_required_version = MINIMUM_MSVC_VERSION
            compiler_info = subprocess.check_output(compiler, stderr=subprocess.STDOUT)
            //修改处2
            match = re.search(r'(\d+)\.(\d+)\.(\d+)', compiler_info.decode(' gbk').strip())
            version = (0, 0, 0) if match is None else match.groups()
    except Exception:
        _, error, _ = sys.exc_info()
        warnings.warn('Error checking compiler version for {}: {}'.format(compiler, error))
        return False

以上就是我对Windows10下安装detectron2的总结以及一些常见的坑的解决方案,我也是第一次安装,查了半天的资料才完成,亲测有效,希望能够帮助各位少走弯路。如文章中出现错误,请大佬指出。

  • 48
    点赞
  • 185
    收藏
    觉得还不错? 一键收藏
  • 94
    评论
### 回答1: 要在Windows 10上安装Detectron2,您需要按照以下步骤操作: 1. 安装Anaconda或Miniconda 2. 创建一个新的conda环境 3. 安装PyTorch 4. 安装COCO API 5. 安装Detectron2 具体步骤可以参考Detectron2官方文档。 ### 回答2: 在Windows 10下安装Detectron2需要进行以下步骤: 1. 确保系统已经安装了C++构建工具。可以通过运行`Visual Studio Installer`来安装所需的C++工具集。 2. 确保Python环境已经正确安装配置。建议使用Anaconda进行Python环境管理。 3. 创建一个新的Python虚拟环境(可选),可以使用以下命令来创建: ``` conda create -n detectron2 python=3.7 ``` 4. 激活新创建的虚拟环境,使用以下命令: ``` conda activate detectron2 ``` 5. 确保虚拟环境已激活后,使用以下命令来安装Detectron2及其依赖: ``` pip install torch torchvision ``` ``` pip install cython ``` ``` pip install opencv-python ``` ``` pip install git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI ``` ``` pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cpu/index.html ``` 6. 安装完成后,使用以下命令来验证Detectron2安装是否成功: ``` python -c "import detectron2; print(detectron2.__version__)" ``` 如果以上步骤都按照正确操作,你应该能够在Windows 10系统上成功安装Detectron2,并且可以在你的Python环境中使用它进行计算机视觉任务的开发和实验。 ### 回答3: 要在Windows 10下安装Detectron2,你可以按照以下步骤进行操作: 1. 首先,在你的Windows 10系统上安装Python。你可以从Python官方网站 (https://www.python.org/downloads/) 下载并安装Python 3.6或以上版本。 2. 安装Microsoft Visual C++ Build Tools。你可以从 https://visualstudio.microsoft.com/visual-cpp-build-tools/ 下载并安装适用于Windows的Build Tools。 3. 安装PyTorch和TorchVision。你可以从PyTorch官方网站 (https://pytorch.org/) 下载适用于Windows的预编译的PyTorch和TorchVision版本,并按照官方指南进行安装。 4. 安装Detectron2的依赖项。打开命令行界面,并使用pip install命令安装以下依赖项: ``` pip install cython pip install pycocotools-windows pip install opencv-python ``` 5. 克隆Detectron2的GitHub代码库。在命令行界面中使用git命令克隆Detectron2的代码库: ``` git clone https://github.com/facebookresearch/detectron2.git ``` 6. 在命令行界面中导航到Detectron2的代码库,并使用以下命令安装Detectron2: ``` cd detectron2 python -m pip install -e . ``` 7. 安装完毕后,你可以在Python中导入Detectron2并开始使用它。例如,你可以使用以下命令导入Detectron2: ```python import detectron2 ``` 这些是在Windows 10下安装Detectron2的基本步骤。请注意,上述步骤可能会因为Detectron2的版本和相关依赖项的更新而略有不同,建议在安装时参考Detectron2的官方文档和GitHub页面上的详细指南。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 94
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值