本文主要是介绍windows10+VS2019+detectron2,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
参考:
win10安装detectron2
https://blog.csdn.net/iamleifeng/article/details/103877581
Windows10下GPU版本的pytorch1.6.0+torchvision0.7.0安装教程(支持CUDA10.2,含whl快速下载地址)
https://blog.csdn.net/xylbill97/article/details/108357819
Windows10下安装detectron2超详细教程(小白视角)
https://blog.csdn.net/weixin_42644340/article/details/109178660
超详细整理Detectron2目标检测源码在Win10下的环境配置
https://blog.csdn.net/weixin_43582457/article/details/108525053
win10下 安装 Detectron2(0.4) (VS2019 + cuda11 + pytorch1.8)
https://blog.csdn.net/haiyangyunbao813/article/details/115106759
win10上安装detectron2==0.4运行Mask R-CNN
https://blog.csdn.net/qq_42315242/article/details/115376377
【扫盲】Detectron2环境搭建(win10)
https://www.bilibili.com/video/BV1jZ4y1W7Nb
Detectron2训练Faster-RCNN&RetinaNet
https://www.bilibili.com/video/BV1Df4y1y7aW
Detectron2训练Mask-RCNN
https://www.bilibili.com/video/BV1mz411i7CN
https://github.com/conansherry/detectron2
https://github.com/facebookresearch/detectron2/releases
VS2019 English
minianaconda默认python3.8
torch-1.6.0+cu101-cp38-cp38-win_amd64
torchvision-0.7.0+cu101-cp38-cp38-win_amd64
(base) C:\Users\yangninghua>python -mpip install C:\Users\yangninghua\Downloads\torch-1.6.0+cu101-cp38-cp38-win_amd64.whl
Processing c:\users\yangninghua\downloads\torch-1.6.0+cu101-cp38-cp38-win_amd64.whl
Requirement already satisfied: numpy in d:\deepglint\miniconda3\lib\site-packages (from torch==1.6.0+cu101) (1.20.2)
Collecting futureDownloading future-0.18.2.tar.gz (829 kB)|████████████████████████████████| 829 kB 89 kB/s
Building wheels for collected packages: futureBuilding wheel for future (setup.py) ... doneCreated wheel for future: filename=future-0.18.2-py3-none-any.whl size=491062 sha256=582222fb8f1328182548756a3497c98a9a61a57453b587d0a9e52f8fffd3c4ddStored in directory: c:\users\yangninghua\appdata\local\pip\cache\wheels\8e\70\28\3d6ccd6e315f65f245da085482a2e1c7d14b90b30f239e2cf4
Successfully built future
Installing collected packages: future, torch
Successfully installed future-0.18.2 torch-1.6.0+cu101(base) C:\Users\yangninghua>python -mpip install "C:\Users\yangninghua\Downloads\torchvision-0.7.0+cu101-cp38-cp38-win_amd64.whl"
Processing c:\users\yangninghua\downloads\torchvision-0.7.0+cu101-cp38-cp38-win_amd64.whl
Requirement already satisfied: numpy in d:\deepglint\miniconda3\lib\site-packages (from torchvision==0.7.0+cu101) (1.20.2)
Requirement already satisfied: torch==1.6.0 in d:\deepglint\miniconda3\lib\site-packages (from torchvision==0.7.0+cu101) (1.6.0+cu101)
Requirement already satisfied: pillow>=4.1.1 in d:\deepglint\miniconda3\lib\site-packages (from torchvision==0.7.0+cu101) (8.2.0)
Requirement already satisfied: future in d:\deepglint\miniconda3\lib\site-packages (from torch==1.6.0->torchvision==0.7.0+cu101) (0.18.2)
Installing collected packages: torchvision
Successfully installed torchvision-0.7.0+cu101(base) C:\Users\yangninghua>python
Python 3.8.3 (default, May 19 2020, 06:50:17) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> touch.__version__
Traceback (most recent call last):File "<stdin>", line 1, in <module>
NameError: name 'touch' is not defined
>>> torch.__version__
'1.6.0+cu101'
>>> torch.cuda.is_available()
True
>>> torch.version.cuda
'10.1'
>>> torch.backends.cudnn.version()
7604
>>> torch.cuda.get_device_name(0)
'GeForce GTX 1060'
>>>
2.5下载包
https://github.com/facebookresearch/detectron2/commit/2455e4790f470bba54299c049410fc0713ae7529
fvcore-master.zip
https://github.com/facebookresearch/fvcore
cocoapi-master.zip
https://github.com/philferriere/cocoapi
3. 添加path
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.28.29910\bin\Hostx64\x64
4.因为之前安装过vs2015,所以需要
SET MSSdk=1
SET DISTUTILS_USE_SDK=1
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvarsall.bat" amd64 -vcvars_ver=14.28
(base) C:\Users\yangninghua>cl
用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.28.29913 版
版权所有(C) Microsoft Corporation。保留所有权利。用法: cl [ 选项... ] 文件名... [ /link 链接选项... ](base) C:\Users\yangninghua>SET MSSdk=1(base) C:\Users\yangninghua>SET DISTUTILS_USE_SDK=1(base) C:\Users\yangninghua>call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvarsall.bat" amd64 -vcvars_ver=14.28
**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.9.2
** Copyright (c) 2021 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64
5.
安装cocoapi
cd coco/PythonAPI
python setup.py build_ext --inplace
python setup.py build_ext install
6.
安装fvcore:
python setup.py build --force develop
7.
安装detectron2
python setup.py build --force develop
出错就:python setup.py clean --all
还是出错:
FAILED: D:/win10_code/detectron2/build/temp.win-amd64-3.8/Release/win10_code/detectron2/detectron2/layers/csrc/deformable/deform_conv_cuda_kernel.obj
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin\nvcc -Xcompiler /MD -Xcompiler /wd4819 -Xcompiler /wd4251 -Xcompiler /wd4244 -Xcompiler /wd4267 -Xcompiler /wd4275 -Xcompiler /wd4018 -Xcompiler /wd4190 -Xcompiler /EHsc -Xcudafe --diag_suppress=base_class_has_different_dll_interface -Xcudafe --diag_suppress=field_without_dll_interface -Xcudafe --diag_suppress=dll_interface_conflict_none_assumed -Xcudafe --diag_suppress=dll_interface_conflict_dllexport_assumed -DWITH_CUDA -ID:\win10_code\detectron2\detectron2\layers\csrc -ID:\deepglint\Miniconda3\lib\site-packages\torch\include -ID:\deepglint\Miniconda3\lib\site-packages\torch\include\torch\csrc\api\include -ID:\deepglint\Miniconda3\lib\site-packages\torch\include\TH -ID:\deepglint\Miniconda3\lib\site-packages\torch\include\THC "-IC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\include" -ID:\deepglint\Miniconda3\include -ID:\deepglint\Miniconda3\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.28.29910\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.28.29910\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\cppwinrt" -c D:\win10_code\detectron2\detectron2\layers\csrc\deformable\deform_conv_cuda_kernel.cu -o D:\win10_code\detectron2\build\temp.win-amd64-3.8\Release\win10_code\detectron2\detectron2\layers\csrc\deformable\deform_conv_cuda_kernel.obj -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr -O3 -DCUDA_HAS_FP16=1 -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=_C -D_GLIBCXX_USE_CXX11_ABI=0 -gencode=arch=compute_61,code=sm_61
D:/deepglint/Miniconda3/lib/site-packages/torch/include\c10/util/ThreadLocalDebugInfo.h(12): warning: modifier is ignored on an enum specifierD:/win10_code/detectron2/detectron2/layers/csrc/deformable/deform_conv_cuda_kernel.cu(104): error: calling a __host__ function("__floorf") from a __device__ function("deformable_im2col_bilinear<float> ") is not allowedD:/win10_code/detectron2/detectron2/layers/csrc/deformable/deform_conv_cuda_kernel.cu(104): error: identifier "__floorf" is undefined in device codeD:/win10_code/detectron2/detectron2/layers/csrc/deformable/deform_conv_cuda_kernel.cu(105): error: calling a __host__ function("__floorf") from a __device__ function("deformable_im2col_bilinear<float> ") is not allowedD:/win10_code/detectron2/detectron2/layers/csrc/deformable/deform_conv_cuda_kernel.cu(105): error: identifier "__floorf" is undefined in device codeD:/deepglint/Miniconda3/lib/site-packages/torch/include\c10/util/Half-inl.h(31): error: calling a __host__ function("__floorf") from a __device__ function("deformable_im2col_bilinear< ::c10::Half> ") is not allowedD:/deepglint/Miniconda3/lib/site-packages/torch/include\c10/util/Half-inl.h(31): error: identifier "__floorf" is undefined in device codeD:/deepglint/Miniconda3/lib/site-packages/torch/include\c10/util/Half-inl.h(31): error: calling a __host__ function("__floorf") from a __device__ function("deformable_im2col_bilinear< ::c10::Half> ") is not allowedD:/deepglint/Miniconda3/lib/site-packages/torch/include\c10/util/Half-inl.h(31): error: identifier "__floorf" is undefined in device codeD:/win10_code/detectron2/detectron2/layers/csrc/deformable/deform_conv_cuda_kernel.cu(146): error: calling a __host__ function("__floorf") from a __device__ function("get_gradient_weight<float> ") is not allowedD:/win10_code/detectron2/detectron2/layers/csrc/deformable/deform_conv_cuda_kernel.cu(146): error: identifier "__floorf" is undefined in device codeD:/win10_code/detectron2/detectron2/layers/csrc/deformable/deform_conv_cuda_kernel.cu(147): error: calling a __host__ function("__floorf") from a __device__ function("get_gradient_weight<float> ") is not allowedD:/win10_code/detectron2/detectron2/layers/csrc/deformable/deform_conv_cuda_kernel.cu(147): error: identifier "__floorf" is undefined in device codeD:/deepglint/Miniconda3/lib/site-packages/torch/include\c10/util/Half-inl.h(31): error: calling a __host__ function("__floorf") from a __device__ function("get_gradient_weight< ::c10::Half> ") is not allowedD:/deepglint/Miniconda3/lib/site-packages/torch/include\c10/util/Half-inl.h(31): error: identifier "__floorf" is undefined in device codeD:/deepglint/Miniconda3/lib/site-packages/torch/include\c10/util/Half-inl.h(31): error: calling a __host__ function("__floorf") from a __device__ function("get_gradient_weight< ::c10::Half> ") is not allowedD:/deepglint/Miniconda3/lib/site-packages/torch/include\c10/util/Half-inl.h(31): error: identifier "__floorf" is undefined in device codeD:/win10_code/detectron2/detectron2/layers/csrc/deformable/deform_conv_cuda_kernel.cu(178): error: calling a __host__ function("__floorf") from a __device__ function("get_coordinate_weight<float> ") is not allowedD:/win10_code/detectron2/detectron2/layers/csrc/deformable/deform_conv_cuda_kernel.cu(178): error: identifier "__floorf" is undefined in device codeD:/win10_code/detectron2/detectron2/layers/csrc/deformable/deform_conv_cuda_kernel.cu(179): error: calling a __host__ function("__floorf") from a __device__ function("get_coordinate_weight<float> ") is not allowedD:/win10_code/detectron2/detectron2/layers/csrc/deformable/deform_conv_cuda_kernel.cu(179): error: identifier "__floorf" is undefined in device codeD:/deepglint/Miniconda3/lib/site-packages/torch/include\c10/util/Half-inl.h(31): error: calling a __host__ function("__floorf") from a __device__ function("get_coordinate_weight< ::c10::Half> ") is not allowedD:/deepglint/Miniconda3/lib/site-packages/torch/include\c10/util/Half-inl.h(31): error: identifier "__floorf" is undefined in device codeD:/deepglint/Miniconda3/lib/site-packages/torch/include\c10/util/Half-inl.h(31): error: calling a __host__ function("__floorf") from a __device__ function("get_coordinate_weight< ::c10::Half> ") is not allowedD:/deepglint/Miniconda3/lib/site-packages/torch/include\c10/util/Half-inl.h(31): error: identifier "__floorf" is undefined in device codeD:/win10_code/detectron2/detectron2/layers/csrc/deformable/deform_conv_cuda_kernel.cu(673): error: calling a __host__ function("__floorf") from a __device__ function("dmcn_im2col_bilinear<float> ") is not allowedD:/win10_code/detectron2/detectron2/layers/csrc/deformable/deform_conv_cuda_kernel.cu(673): error: identifier "__floorf" is undefined in device codeD:/win10_code/detectron2/detectron2/layers/csrc/deformable/deform_conv_cuda_kernel.cu(674): error: calling a __host__ function("__floorf") from a __device__ function("dmcn_im2col_bilinear<float> ") is not allowedD:/win10_code/detectron2/detectron2/layers/csrc/deformable/deform_conv_cuda_kernel.cu(674): error: identifier "__floorf" is undefined in device codeD:/deepglint/Miniconda3/lib/site-packages/torch/include\c10/util/Half-inl.h(31): error: calling a __host__ function("__floorf") from a __device__ function("dmcn_im2col_bilinear< ::c10::Half> ") is not allowedD:/deepglint/Miniconda3/lib/site-packages/torch/include\c10/util/Half-inl.h(31): error: identifier "__floorf" is undefined in device codeD:/deepglint/Miniconda3/lib/site-packages/torch/include\c10/util/Half-inl.h(31): error: calling a __host__ function("__floorf") from a __device__ function("dmcn_im2col_bilinear< ::c10::Half> ") is not allowedD:/deepglint/Miniconda3/lib/site-packages/torch/include\c10/util/Half-inl.h(31): error: identifier "__floorf" is undefined in device codeD:/win10_code/detectron2/detectron2/layers/csrc/deformable/deform_conv_cuda_kernel.cu(715): error: calling a __host__ function("__floorf") from a __device__ function("dmcn_get_gradient_weight<float> ") is not allowedD:/win10_code/detectron2/detectron2/layers/csrc/deformable/deform_conv_cuda_kernel.cu(715): error: identifier "__floorf" is undefined in device codeD:/win10_code/detectron2/detectron2/layers/csrc/deformable/deform_conv_cuda_kernel.cu(716): error: calling a __host__ function("__floorf") from a __device__ function("dmcn_get_gradient_weight<float> ") is not allowedD:/win10_code/detectron2/detectron2/layers/csrc/deformable/deform_conv_cuda_kernel.cu(716): error: identifier "__floorf" is undefined in device codeD:/deepglint/Miniconda3/lib/site-packages/torch/include\c10/util/Half-inl.h(31): error: calling a __host__ function("__floorf") from a __device__ function("dmcn_get_gradient_weight< ::c10::Half> ") is not allowedD:/deepglint/Miniconda3/lib/site-packages/torch/include\c10/util/Half-inl.h(31): error: identifier "__floorf" is undefined in device codeD:/deepglint/Miniconda3/lib/site-packages/torch/include\c10/util/Half-inl.h(31): error: calling a __host__ function("__floorf") from a __device__ function("dmcn_get_gradient_weight< ::c10::Half> ") is not allowedD:/deepglint/Miniconda3/lib/site-packages/torch/include\c10/util/Half-inl.h(31): error: identifier "__floorf" is undefined in device codeD:/win10_code/detectron2/detectron2/layers/csrc/deformable/deform_conv_cuda_kernel.cu(747): error: calling a __host__ function("__floorf") from a __device__ function("dmcn_get_coordinate_weight<float> ") is not allowedD:/win10_code/detectron2/detectron2/layers/csrc/deformable/deform_conv_cuda_kernel.cu(747): error: identifier "__floorf" is undefined in device codeD:/win10_code/detectron2/detectron2/layers/csrc/deformable/deform_conv_cuda_kernel.cu(748): error: calling a __host__ function("__floorf") from a __device__ function("dmcn_get_coordinate_weight<float> ") is not allowedD:/win10_code/detectron2/detectron2/layers/csrc/deformable/deform_conv_cuda_kernel.cu(748): error: identifier "__floorf" is undefined in device codeD:/deepglint/Miniconda3/lib/site-packages/torch/include\c10/util/Half-inl.h(31): error: calling a __host__ function("__floorf") from a __device__ function("dmcn_get_coordinate_weight< ::c10::Half> ") is not allowedD:/deepglint/Miniconda3/lib/site-packages/torch/include\c10/util/Half-inl.h(31): error: identifier "__floorf" is undefined in device codeD:/deepglint/Miniconda3/lib/site-packages/torch/include\c10/util/Half-inl.h(31): error: calling a __host__ function("__floorf") from a __device__ function("dmcn_get_coordinate_weight< ::c10::Half> ") is not allowedD:/deepglint/Miniconda3/lib/site-packages/torch/include\c10/util/Half-inl.h(31): error: identifier "__floorf" is undefined in device code48 errors detected in the compilation of "C:/Users/YANGNI~1/AppData/Local/Temp/tmpxft_0000260c_00000000-10_deform_conv_cuda_kernel.cpp1.ii".
deform_conv_cuda_kernel.cu
参考这个老哥的:
https://blog.csdn.net/qq_42315242/article/details/115376377
解决
D:\win10_code\detectron2\detectron2\layers\csrc\ROIAlignRotated\ROIAlignRotated_cuda.cu
D:\win10_code\detectron2\detectron2\layers\csrc\deformable\deform_conv_cuda_kernel.cu
修改 ceil改为ceilf、floor改为floorf
python -mpip install tensorboard==2.4.1 -i https://pypi.tuna.tsinghua.edu.cn/simple/
D:\win10_code\detectron2>python setup.py build --force develop
虽然安装成功,遇到两个问题:
ERROR: detectron2 0.4 requires cloudpickle, which is not installed.
ERROR: detectron2 0.4 has requirement pycocotools>=2.0.2, but you'll have pycocotools 2.0 which is incompatible.
换成这个:
https://github.com/ppwwyyxx/cocoapi
然后:
D:\win10_code\cocoapi-2.0.2\PythonAPI>python -mpip list
Package Version Location
---------------------- ------------------- ------------------------
absl-py 0.12.0
antlr4-python3-runtime 4.8
cachetools 4.2.1
certifi 2020.4.5.1
cffi 1.14.0
chardet 3.0.4
cloudpickle 1.6.0
conda 4.8.3
conda-package-handling 1.7.0
cryptography 2.9.2
cycler 0.10.0
Cython 0.29.22
detectron2 0.4 d:\win10_code\detectron2
future 0.18.2
fvcore 0.1.5 d:\win10_code\fvcore
google-auth 1.28.0
google-auth-oauthlib 0.4.4
grpcio 1.36.1
idna 2.9
iopath 0.1.7
kiwisolver 1.3.1
Markdown 3.3.4
matplotlib 3.4.1
menuinst 1.4.16
numpy 1.20.2
oauthlib 3.1.0
omegaconf 2.1.0.dev22
opencv-contrib-python 4.5.1.48
opencv-python 4.5.1.48
pandas 1.2.3
Pillow 8.2.0
pip 20.0.2
portalocker 2.3.0
protobuf 3.15.7
pyasn1 0.4.8
pyasn1-modules 0.2.8
pycocotools 2.0.2
pycosat 0.6.3
pycparser 2.20
pydot 1.4.2
pyOpenSSL 19.1.0
pyparsing 2.4.7
PySocks 1.7.1
python-dateutil 2.8.1
pytz 2021.1
pywin32 227
pyyaml 5.4.1
requests 2.23.0
requests-oauthlib 1.3.0
rsa 4.7.2
ruamel-yaml 0.15.87
setuptools 46.4.0.post20200518
six 1.14.0
tabulate 0.8.9
tensorboard 2.4.1
tensorboard-plugin-wit 1.8.0
termcolor 1.1.0
torch 1.6.0+cu101
torchvision 0.7.0+cu101
tqdm 4.46.0
urllib3 1.25.8
Werkzeug 1.0.1
wheel 0.34.2
win-inet-pton 1.1.0
wincertstore 0.2
yacs 0.1.8
测试:
可以运行:
下载:https://dl.fbaipublicfiles.com/detectron2/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_1x/137260431/model_final_a54504.pkl
D:\win10_code\detectron2>python demo/demo.py --config-file configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_1x.yaml --webcam --opts MODEL.WEIGHTS model_final_a54504.pkl
[32m[04/08 00:35:31 detectron2]: [0mArguments: Namespace(confidence_threshold=0.5, config_file='configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_1x.yaml', input=None, opts=['MODEL.WEIGHTS', 'model_final_a54504.pkl'], output=None, video_input=None, webcam=True)
[32m[04/08 00:35:42 fvcore.common.checkpoint]: [0mLoading checkpoint from model_final_a54504.pkl
[32m[04/08 00:35:42 fvcore.common.checkpoint]: [0mReading a file from 'Detectron2 Model Zoo'
0it [00:00, ?it/s]d:\win10_code\detectron2\detectron2\modeling\roi_heads\fast_rcnn.py:154: UserWarning: This overload of nonzero is deprecated:nonzero()
Consider using one of the following signatures instead:nonzero(*, bool as_tuple) (Triggered internally at ..\torch\csrc\utils\python_arg_parser.cpp:766.)filter_inds = filter_mask.nonzero()
这个警告我原本以为是因为没改这个,但是不是,所有我又改回来了
D:\~\Miniconda3\Lib\site-packages\torch\utils\cpp_extension.py
警告是因为这个:
https://github.com/pytorch/vision/issues/2704
https://github.com/pytorch/pytorch/issues/38718
https://github.com/facebookresearch/detectron2/pull/1974
修改方案:
The warning was because of the PyTorch function nonzero. This warning can be removed by adding the as_tuple argument in the function.In the Detectron2/layers/wrappers.py:"return x.nonzero().unbind(1)" needs to be replaced by
"return torch.nonzero(x, as_tuple=True)"And in the file Detectron2/modeling/roi_heads/fast_rcnn.py:"filter_inds = filter_mask.nonzero()" needs to be replaced by
"filter_inds=torch.nonzero(filter_mask, as_tuple=False)"
or更改pytorch1.7 pytorch1.8等
这篇关于windows10+VS2019+detectron2的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!