概述
想安装detectron2这个目标检测框架,竟然不能直接用pip安装。
只能按照安装手册
运行如下命令:
git clone https://github.com/facebookresearch/detectron2.git
python -m pip install -e detectron2
但是却出了问题:
ninja出错
问题就是ninja -v 出错,安装了ninja后还是出错,在本地目录下运行没问题,出错:
subprocess.CalledProcessError: Command ‘[‘ninja‘, ‘-v‘]‘ returned non-zero exit status 1
开始以为是运行 ninja -v出现的问题,最后花费了很大功夫还是没解决。
最后干脆把ninja关闭了。
就是把detectron2目录下setup.py最后一项更改如下:
# cmdclass={"build_ext": torch.utils.cpp_extension.BuildExtension},
cmdclass={"build_ext": torch.utils.cpp_extension.BuildExtension.with_options(use_ninja=False)},
这样就不适用ninja来编译了。
vs 编译出错问题
detectron2layerscsrcnms_rotatednms_rotated_cuda.cu
开始是说
using namespace detectron2;
这句不认识命名空间detectron2
就把这句注释掉了
但是接着说不识别函数:single_box_iou_rotated。
最后发现这个函数在detectron2detectron2layerscsrcbox_iou_rotatedbox_iou_rotated_utils.h
中存在。
最后查找资料,要更改nms_rotated_cuda.cu文件中如下:
#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"
using namespace detectron2;
就是把两个对宏判断去掉:
WITH_CUDA和 WITH_HIP
可能编译的时候没打开这两个宏开关。
最后运行成功了
python -m pip install -e detectron2
这个问题花费了半天才解决。
所以环境搭建这样的问题,确实比较麻烦,有时比调程序找bug麻烦。
最后
以上就是感动酒窝为你收集整理的安装detectron2的一些坑ninja出错vs 编译出错问题的全部内容,希望文章能够帮你解决安装detectron2的一些坑ninja出错vs 编译出错问题所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复