住房和城乡建设部网站施工员,张家口网站建设开发,金华市建设局网站,网站建设的工作内容文章目录 前言下载detectron2安装Visual Studio 2019修改代码 前言
需要下载detectron2的github项目#xff0c;安装vs2019 (强烈建议这个版本#xff0c;其他的版本需要做更多地操作才能成功安装)#xff0c;默认其他环境没问题。
下载detectron2
链接#xff1a;https… 文章目录 前言下载detectron2安装Visual Studio 2019修改代码 前言
需要下载detectron2的github项目安装vs2019 (强烈建议这个版本其他的版本需要做更多地操作才能成功安装)默认其他环境没问题。
下载detectron2
链接https://github.com/facebookresearch/detectron2 也可以克隆到本地
git clone https://github.com/facebookresearch/detectron2.git将prompt的当前路径改为detectron2
cd detectron2安装Visual Studio 2019
官网VS2019 下载社区版安装即可第一次进入这个界面可能需要登录微软账号。 双击运行下载得到的可执行文件安装时选择使用C的桌面开发然后全部默认安装即可。 这里耗时比较久需要十几分钟的样子等待安装完成后不用启动。接下来需要配置一个环境变量。右击此电脑选择属性–高级系统设置–环境变量–系统变量–path–编辑–新建输入
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64注意这个路径要跟自己电脑上的实际情况对应其中的14.29这个编号下一步需要。 接下来在点击winR打开命令行窗口输入cl查看是否有输出。 如上图说明环境变量没有问题此时需要再设置一下编译器。
SET MSSdk1
SET DISTUTILS_USE_SDK1
call “C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat” amd64 -vcvars_ver14.29运行后结果如图。
修改代码
先安装fvcore包可以直接使用pip安装
pip install fvcore -i https://pypi.mirrors.ustc.edu.cn/simple/也可以先下载或者git克隆fvcore的github包然后安装。
git clone https://github.com/facebookresearch/fvcore.git
cd fvcore
python setup.py build --force develop接下来需要修改一些文件里的内容。
在Anaconda的安装路径里D:\Anaconda3\envs\pt2.0\Lib\site-packages\torch\utils\cpp_extension.py修改在文件中的SUBPROCESS_DECODE_ARGS参数为gbk上边是注释掉的可以使用查找来找这个变量。注意路径中的虚拟环境名与自己实际情况对应。
# SUBPROCESS_DECODE_ARGS (,) if IS_WINDOWS else ()
SUBPROCESS_DECODE_ARGS (gbk,) if IS_WINDOWS else ()如果不能找到这个变量那可能是pytorch版本不一样导致的此时还可以有另一种解决办法修改如下
# match re.search(r(\d)\.(\d)\.(\d), compiler_info.decode(*SUBPROCESS_DECODE_ARGS).strip())
match re.search(r(\d)\.(\d)\.(\d), compiler_info.decode(‘gbk’).strip())不同的pytorch版本可能存在一些小差异但基本这条语句类似。
继续修改当前环境里的D:\Anaconda3\envs\pt2.0\Lib\site-packages\torch\include\torch\csrc\jit\runtime\argument_spec.h修改如下
// static constexpr size_t ARG_SPEC_DEPTH_LIMIT 128;
static const size_t ARG_SPEC_DEPTH_LIMIT 128;注意这里如果是加注释的话要注意注释格式中python与c写法的不同。
继续修改当前环境里的D:\Anaconda3\envs\pt2.0\Lib\site-packages\torch\include\torch\csrc\jit\ir\ir.h注释掉下边这句一些版本的pytorch里边可能直接没有这条语句。
// static constexpr Symbol Kind ::c10::prim::profile_optional修改detectron2里的I:\detectron2\detectron2\layers\csrc\ROIAlignRotated\ROIAlignRotated_cuda.cu将所有的ceil替换为ceilf这里要注意区分大小写有两处大写的Ceil不要替换在使用一键替换时一定要严格限制大小写。继续修改detectron2里的I:\detectron2\detectron2\layers\csrc\deformable\deform_conv_cuda_kernel.cu将所有的floor改为floorf。继续修改detectron2里的I:\detectron2\detectron2\layers\csrc\cocoeval\cocoeval.cpp。
// localtime_r(rawtime, local_time);
localtime_s(local_time,rawtime);继续修改detectron2里的I:\detectron2\detectron2\layers\csrc\nms_rotated\nms_rotated_cuda.cu其中对头文件定义中注释掉一些添加上一些如下
// Copyright (c) Facebook, Inc. and its affiliates.
#include ATen/ATen.h
#include ATen/cuda/CUDAContext.h
#include c10/cuda/CUDAGuard.h
#include ATen/cuda/CUDAApplyUtils.cuh
/*#ifdef WITH_CUDA
#include ../box_iou_rotated/box_iou_rotated_utils.h
#endif
// TODO avoid this when pytorch supports same directory hipification
#ifdef WITH_HIP
#include box_iou_rotated/box_iou_rotated_utils.h
#endif*/
#include box_iou_rotated/box_iou_rotated_utils.h此时prompt在detectron2路径下运行
python setup.py build develop如下则表示已经安装成功了。