Detectron2安装踩坑记录(比较详细版)

Detectron2安装踩坑记录(比较详细版),第1张

目录

第一章 创建一个detectron2的环境

1.1打开Prompt,然后输入

1.2激活环境

第二章 安装pytorch1.9.0

2.1依据自身环境查看版本

2.2安装pytorch的相关命令

2.3报错汇总解决

2.4测试pytorch安装效果

第三章 安装其他的包 

3.1安装opencv

3.2安装pycocotools

3.2.1报错参考

3.2.2安装成功实例

 第四章 安装Detectron2

4.1 进行剩下的几个pip包的安装

4.2根据自己安装的Pytorch、CUDA版本,选择对应的 detectron2 版本安装

4.3报错与解决

 祝大家都可以成功安装,一起加油


 

 

参考:利用 Conda 安装深度学习框架 Pytorch (qq.com)https://mp.weixin.qq.com/s/khV6TdmiQwj0_b7cih5wAQ

第一章 创建一个detectron2的环境

我使用的是AnacondaPrompt(Anaconda3)命令行进行安装以下所有的东西的,首先我们要进行创建一个环境

1.1打开Prompt,然后输入
conda create -n detectron2 python=3.8 -y
1.2激活环境
activate detectron2

如果这里失败了可以再试试。

source activate detectron2

 以下的 *** 作都是基于搭建完detectron2的conda环境来进行的

 

第二章 安装pytorch1.9.0 2.1依据自身环境查看版本

我们首先要看一下自己的GPU版本(当然如若没有GPU或者不用GPU,选择CPU版本也可以)

打开CMD,输入nvcc --version,这里我们看到我们的cuda版本为11.1,故选择cuda 11.1对应的pytorch

 

此时要去官网看一下Previous Pytorch Versions(先前的pytorch版本)

 

 往下翻——找到我们所需的v1.9.0

然后我们找到cuda11.1这里的命令行

# CUDA 11.1
pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html

 

当然如果你是最新版本的cuda11.3可以去官网首页查找命令

pytorch官网

2.2安装pytorch的相关命令

最新的cuda11.3以conda方式安装

conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch

cuda11.3以pip3方式安装

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

安装torch1.9.0的其他版本 

# CUDA 11.1
pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html
# CUDA 10.2
pip install torch==1.9.0+cu102 torchvision==0.10.0+cu102 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html
# CPU only
pip install torch==1.9.0+cpu torchvision==0.10.0+cpu torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html
2.3报错汇总解决

安装pycocotools2.0.2这一块这里我遇到的问题基本上就是各种http error连接失败,这里推荐几种方法进行安装

第一种可以考虑国内清华镜像源进行安装,这种方法可以推荐,但是我自己却失败了。

 (76条消息) pytorch+GPU 清华镜像源安装(anaconda)_一念成人的博客-CSDN博客_pytorch清华镜像源https://blog.csdn.net/qq_45871272/article/details/106807642?ops_request_misc=&request_id=&biz_id=102&utm_term=pytorch%E6%9B%B4%E6%8D%A2%E6%B8%85%E5%8D%8E%E9%95%9C%E5%83%8F%E6%BA%90&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-3-106807642.142%5Ev9%5Epc_search_result_control_group,157%5Ev4%5Econtrol&spm=1018.2226.3001.4187

(76条消息) pytorch镜像安装【清华源】_Activewaste的博客-CSDN博客_pytorch清华镜像源https://blog.csdn.net/qq_41375609/article/details/103574507?ops_request_misc=&request_id=&biz_id=102&utm_term=pytorch%E6%9B%B4%E6%8D%A2%E6%B8%85%E5%8D%8E%E9%95%9C%E5%83%8F%E6%BA%90&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-1-103574507.142%5Ev9%5Epc_search_result_control_group,157%5Ev4%5Econtrol&spm=1018.2226.3001.4187
(76条消息) 清华源镜像安装pytorch_樊城的博客-CSDN博客https://blog.csdn.net/weixin_44753371/article/details/103145696?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165012449416780269821658%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=165012449416780269821658&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v1~rank_v31_ecpm-4-103145696.142%5Ev9%5Epc_search_result_control_group,157%5Ev4%5Econtrol&utm_term=pytorch%E6%9B%B4%E6%8D%A2%E6%B8%85%E5%8D%8E%E9%95%9C%E5%83%8F%E6%BA%90&spm=1018.2226.3001.4187

 我自己的方法其实是离线下载到本地再使用pip命令进行安装——即为把上面官方的代码

# CUDA 11.1
pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html

其中的地址提取出来

https://download.pytorch.org/whl/torch_stable.html

进入其下载主页找到——

torch==1.9.0+cu111  

torchaudio==0.9.0  

torchvision==0.10.0+cu111  
 

这三个对应的文件,点击下载到本地(可以使用迅雷接管下载)

https://download.csdn.net/download/blink182007/85158206https://download.csdn.net/download/blink182007/85158206将这条代码的三个文件,分别下载,分别独立安装——实现torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio==0.9.0本地离线安装,一共三个文件可以使用迅雷进行接管下载,也可以在浏览器下载。

下载完成以后使用pip install +文件路径名进行安装(实例 pip install E:\anacondalib\torch-1.9.0+cu111-cp38-cp38-win_amd64.whl)即可,如若遇见报错的情况——如安装pytorchvision时,可以改为pip3 install进行安装即可

然后就安装完成了

 

2.4测试pytorch安装效果

这里我们再测试一下安装效果

第三章 安装其他的包 

这里我们再下载detectron2的文件

https://download.csdn.net/download/blink182007/85158248https://download.csdn.net/download/blink182007/85158248conansherry/detectron2: detectron2 windows build (github.com)https://github.com/conansherry/detectron2

3.1安装opencv
pip install opencv-python

我们打开pycharm发现还有很多环境没有装完,于是在pycharm终端开始安装(同样的使用pip命令),当然也可以使用anaconda进入你所创建的detectron2环境 ,然后搜索安装包进行安装

 

 

3.2安装pycocotools 3.2.1报错参考

我在安装pycocotools的时候遇见报错了ERROR如下:

ERROR: Command errored out with exit status 1:
   command: 'D:\Anaconda3\envs\detectron2\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\14508\\AppData\\Local\\Temp\\pip-install-45g_9a3k\\
pycocotools_af87afd1e057430c8b5cda64f904bec5\\setup.py'"'"'; __file__='"'"'C:\\Users\\14508\\AppData\\Local\\Temp\\pip-install-45g_9a3k\\pycocotools_af87afd1e057430c8b5cda64f904bec5\\s
etup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\14508\AppData\Local\Temp\pip-wheel-w8o8_8yo'
       cwd: C:\Users\14508\AppData\Local\Temp\pip-install-45g_9a3k\pycocotools_af87afd1e057430c8b5cda64f904bec5\
  Complete output (18 lines):
  D:\Anaconda3\envs\detectron2\lib\site-packages\setuptools\installer.py:27: SetuptoolsDeprecationWarning: setuptools.installer is deprecated. Requirements should be satisfied by a PEP 517 installer.
    warnings.warn(
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib.win-amd64-3.8
  creating build\lib.win-amd64-3.8\pycocotools
  copying pycocotools\coco.py -> build\lib.win-amd64-3.8\pycocotools
  copying pycocotools\cocoeval.py -> build\lib.win-amd64-3.8\pycocotools
  copying pycocotools\mask.py -> build\lib.win-amd64-3.8\pycocotools
  copying pycocotools\__init__.py -> build\lib.win-amd64-3.8\pycocotools
  running build_ext
  cythoning pycocotools/_mask.pyx to pycocotools\_mask.c
  c:\users\14508\appdata\local\temp\pip-install-45g_9a3k\pycocotools_af87afd1e057430c8b5cda64f904bec5\.eggs\cython-0.29.28-py3.8.egg\Cython\Compiler\Main.py:369: FutureWarning: Cython 
directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: C:\Users\14508\AppData\Local\Temp\pip-install-45g_9a3k\pycocotools_af87afd1e057430c8b5cda64f904bec5\pycocotools\_mask.pyx
    tree = Parsing.p_module(s, pxd, full_module_name)
  building 'pycocotools._mask' extension
  error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
  ----------------------------------------
  ERROR: Failed building wheel for pycocotools
  Running setup.py clean for pycocotools
Failed to build pycocotools
Installing collected packages: cython, pycocotools
    Running setup.py install for pycocotools ... error
    ERROR: Command errored out with exit status 1:
     command: 'D:\Anaconda3\envs\detectron2\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\14508\\AppData\\Local\\Temp\\pip-install-45g_9a3k
\\pycocotools_af87afd1e057430c8b5cda64f904bec5\\setup.py'"'"'; __file__='"'"'C:\\Users\\14508\\AppData\\Local\\Temp\\pip-install-45g_9a3k\\pycocotools_af87afd1e057430c8b5cda64f904bec5\
\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().repla
ce('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\14508\AppData\Local\Temp\pip-record-o8noxmzx\install-record.txt' --single-version-externally-managed --compile --install-headers 'D:\Anaconda3\envs\detectron2\Include\pycocotools'
         cwd: C:\Users\14508\AppData\Local\Temp\pip-install-45g_9a3k\pycocotools_af87afd1e057430c8b5cda64f904bec5\
    Complete output (16 lines):
    running install
    D:\Anaconda3\envs\detectron2\lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
      warnings.warn(
    running build
    running build_py
    creating build
    creating build\lib.win-amd64-3.8
    creating build\lib.win-amd64-3.8\pycocotools
    copying pycocotools\coco.py -> build\lib.win-amd64-3.8\pycocotools
    copying pycocotools\cocoeval.py -> build\lib.win-amd64-3.8\pycocotools
    copying pycocotools\mask.py -> build\lib.win-amd64-3.8\pycocotools
    copying pycocotools\__init__.py -> build\lib.win-amd64-3.8\pycocotools
    running build_ext
    skipping 'pycocotools\_mask.c' Cython extension (up-to-date)
    building 'pycocotools._mask' extension
    error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
    ----------------------------------------

第一种采取git方式进行安装方法我失败了,安装完git以后依旧失败

 参考如下:

 (75条消息) 安装pycocoapi, pip install "git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI"出错_W.S.Yin的博客-CSDN博客https://blog.csdn.net/qq_36679208/article/details/105070957

 

参考下面五个攻略,来自:
(76条消息) 安装 detectron2时要求安装pycocotools2.0.2_Andy-Miao的博客-CSDN博客https://blog.csdn.net/mmww1994/article/details/108503168

 (76条消息) 【已解决】error: Microsoft Visual C++ 14.0 or greater is required_ViatorSun的博客-CSDN博客https://blog.csdn.net/ViatorSun/article/details/118699938

 (76条消息) 解决 ERROR: Command errored out with exit status 128: git clone -q_椰子炖我的博客-CSDN博客https://blog.csdn.net/Peggiehu/article/details/120658066

 (76条消息) Visual C++ 2015 build tools 无法安装,提示缺少包_2∧10的博客-CSDN博客https://blog.csdn.net/qq_43412950/article/details/123056804

 (76条消息) Windows下安装pycocotools(本人亲测,可以解决)_从现在开始壹并超的博客-CSDN博客_安装pycocotoolshttps://blog.csdn.net/m0_45971439/article/details/118332681?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-8.pc_relevant_aa&spm=1001.2101.3001.4242.5&utm_relevant_index=11

3.2.2安装成功实例

经历各种以后困难,pycocotools终于安装成功了

 第四章 安装Detectron2

接下来我们安装detectron2


4.1 进行剩下的几个pip包的安装

安装hydra-core pip install hydra-core==1.1

 

 

 

 

安装pip install fvcore==0.1.5.post20220414

 

 

安装pip install omegaconf==2.1.0

 

 接下来我们安装detectron2

4.2根据自己安装的Pytorch、CUDA版本,选择对应的 detectron2 版本安装
# CUDA 11.1
python -m pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu111/torch1.9/index.html

 

# CUDA 10.2
python -m pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu102/torch1.9/index.html

 

# CPU
python -m pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cpu/torch1.9/index.html

(76条消息) Win10下安装Detectron2,超详细教程!_zzy153的博客-CSDN博客_win10安装detectron2https://blog.csdn.net/zzy153/article/details/120693321
(76条消息) Windows10下安装detectron2超详细教程(小白视角)_小白wwj的博客-CSDN博客_detectron2 windows安装https://blog.csdn.net/weixin_42644340/article/details/109178660

首先我们下载detectron的代码

detectron2-master,代码如下,下载以后保存到E盘或者D盘,我个人是新建了一个anacondalib文件夹

https://gitcode.net/mirrors/facebookresearch/detectron2/-/archive/master/detectron2-master.ziphttps://gitcode.net/mirrors/facebookresearch/detectron2/-/archive/master/detectron2-master.zip

 然后我们打开anaconda prompt激活环境

activate detectron2
cd E:\anacondalib\detectron2-master\detectron2-master
E:

 此时我们已经成功激活了环境——

然后我这里是建议直接进行编译,然后根据报错来逐步解决——

4.3报错与解决

我的报错比较多

nms_rotated_cuda.cu
D:/ProgramData/Anaconda3/envs/det/lib/site-packages/torch/include\c10/util/ThreadLocalDebugInfo.h(12): warning: modifier is ignored on an enum specifier
 
E:/Code/open-world-ob-gym/OWOD/detectron2/layers/csrc/nms_rotated/nms_rotated_cuda.cu(14): error: name must be a namespace name
 
E:/Code/open-world-ob-gym/OWOD/detectron2/layers/csrc/nms_rotated/nms_rotated_cuda.cu(68): error: identifier "single_box_iou_rotated" is undefined
          detected during instantiation of "void nms_rotated_cuda_kernel(int, float, const T *, unsigned long long *) [with T=double]"
(105): here
 
E:/Code/open-world-ob-gym/OWOD/detectron2/layers/csrc/nms_rotated/nms_rotated_cuda.cu(68): error: type name is not allowed
          detected during instantiation of "void nms_rotated_cuda_kernel(int, float, const T *, unsigned long long *) [with T=double]"
(105): here
 
E:/Code/open-world-ob-gym/OWOD/detectron2/layers/csrc/nms_rotated/nms_rotated_cuda.cu(68): warning: expression has no effect
          detected during instantiation of "void nms_rotated_cuda_kernel(int, float, const T *, unsigned long long *) [with T=double]"
(105): here
 
E:/Code/open-world-ob-gym/OWOD/detectron2/layers/csrc/nms_rotated/nms_rotated_cuda.cu(58): warning: variable "cur_box" was set but never used
          detected during instantiation of "void nms_rotated_cuda_kernel(int, float, const T *, unsigned long long *) [with T=double]"
(105): here
 
E:/Code/open-world-ob-gym/OWOD/detectron2/layers/csrc/nms_rotated/nms_rotated_cuda.cu(68): error: identifier "single_box_iou_rotated" is undefined
          detected during instantiation of "void nms_rotated_cuda_kernel(int, float, const T *, unsigned long long *) [with T=float]"
(105): here
 
E:/Code/open-world-ob-gym/OWOD/detectron2/layers/csrc/nms_rotated/nms_rotated_cuda.cu(68): error: type name is not allowed
          detected during instantiation of "void nms_rotated_cuda_kernel(int, float, const T *, unsigned long long *) [with T=float]"
(105): here
 
E:/Code/open-world-ob-gym/OWOD/detectron2/layers/csrc/nms_rotated/nms_rotated_cuda.cu(68): warning: expression has no effect
          detected during instantiation of "void nms_rotated_cuda_kernel(int, float, const T *, unsigned long long *) [with T=float]"
(105): here
 
E:/Code/open-world-ob-gym/OWOD/detectron2/layers/csrc/nms_rotated/nms_rotated_cuda.cu(58): warning: variable "cur_box" was set but never used
          detected during instantiation of "void nms_rotated_cuda_kernel(int, float, const T *, unsigned long long *) [with T=float]"
(105): here
 
5 errors detected in the compilation of "C:/Users/miclo/AppData/Local/Temp/tmpxft_00000c50_00000000-7_nms_rotated_cuda.cpp1.ii".
error: command 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin\nvcc.exe' failed with exit status 1

可以参考一下博客内容

Window11 安装detectron2记录贴_Easy.miclover的博客-CSDN博客python setup.py build --force develop出现报错:ir.h(1347): error: member "torch::jit::ProfileOptionalOp::Kind" may not be initialized查阅了许多博客的解决办法就是定位到指定位置,注释掉这一句话但是,接下来编译又出现了好多问题:nms_rotated_cuda.cuD:/ProgramData/Anaconda3/envs/det/lib/site-pac..https://blog.csdn.net/miclover_feng/article/details/121693379?ops_request_misc=&request_id=&biz_id=102&utm_term=nms_rotated_cuda.cu(68):%20error&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-1-121693379.142%5Ev9%5Epc_search_result_control_group,157%5Ev4%5Econtrol&spm=1018.2226.3001.4187这位博主的博客写的非常好,其中的LF可以不必添加,原因参考这篇

win10下detectron2编译安装方法及问题汇总_三毛的二哥的博客-CSDN博客_windows 编译detectron2环境硬件硬件:CPU:Intel®Core™i5-10400F CPU @2.90GHz 2.90GHzGPU: NVIDIA GeForce GTX 1660 Ti (6G显存)内存:16.0GB(15.9GB可用)软件:Visual Studio 2019CUDA10.1,cudnnAnaconda3torch 1.6.0+cu101torchvision 0.7.0+cu101python=3.8.0detectron2准备工作Anaconda3,Visual Studhttps://blog.csdn.net/lishiyu93/article/details/116459114?ops_request_misc=&request_id=&biz_id=102&utm_term=nms_rotated_cuda.cu(13):%20error&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-0-116459114.142%5Ev9%5Epc_search_result_control_group,157%5Ev4%5Econtrol&spm=1018.2226.3001.4187然后我解决完报错以后成功安装

 

Anaconda Prompt输入conda list成功安装 

 

顺便看一下 pycocotools版本为2.0.2

 

 祝大家都可以成功安装,一起加油

 

 

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/723211.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-26
下一篇 2022-04-26

发表评论

登录后才能评论

评论列表(0条)

保存