ubuntu18.04下pytorch版Maskrcnn编译错误汇总

文章详细记录了在Ubuntu18.04上使用conda环境配置PyTorch和MaskRCNN过程中遇到的CUDA版本不匹配、apex安装失败、模块找不到等错误,以及相应的解决方法,包括降级CUDA版本、安装特定版本的opencv-python和cityscapesscripts等。
摘要由CSDN通过智能技术生成

搞了一整天,终于把maskrcnn的官方实例调通了,被cuda11.2坑了,不要靠近11.2,会变得不幸

1 anconda环境配置

  • Ubuntu18.04
  • anconda+cuda10.1+cudnn10.1
  • python3.7
conda create -n maskrcnn python=3.7
conda activate maskrcnn

conda install ipython pip
conda install pytorch torchvision cudatoolkit=10.1 -c pytorch

其他都参考官方
https://github.com/facebookresearch/maskrcnn-benchmark/blob/main/INSTALL.md


2 bug及解决办法

2.1 Detected CUDA version (11.2) mismatches the version that was used to compile PyTorch(10.2)

运行python setup.py build develop遇到的报错

本质上是因为系统装的cuda是11.2版本的,conda环境中pytorch是和cudatoolkit=10.2关联的,所以安装的时候一定要对应
(在这里被坑了半天,cuda11.2找不到对应的pytorch,好不容易装上了还是有一大堆报错,我又不得不装了cuda10.1,搞多版本切换)


2.2 error: legacy-install-failure × Encountered error while trying to install package.╰─> apex

安装apex的报错

在这里插入图片描述

pip3 install -v --no-cache-dir ./

然而这样搞好以后,又出现新bug
AttributeError: module ‘torch.distributed’ has no attribute ‘_all_gather_base’

参考https://blog.csdn.net/qq_44741914/article/details/128087328
到github下载22.04dev版本,就没问题了


2.3 ModuleNotFoundError: No module named ‘xxx’

首先检查当前conda环境下是否已经安装,如果安装了,在jupyter notebook中还是找不到,检查一下内核对不对
在这里插入图片描述
如果只有一个python3,用如下命令安装再重启

conda install nb_conda

2.4 module ‘torch._six’ has no attribute ‘PY37’

根据安装的pytorch版本找到路径
/home/slender/anaconda3/pkgs/pytorch-1.13.1-py3.7_cpu_0/lib/python3.7/site-packages/torch/_six.py

修改:

import math
import sys
 
inf = math.inf
nan = math.nan
string_classes = (str, bytes)
PY37 = sys.version_info[0] == 3 and sys.version_info[1] >= 7

2.5 cannot import name ‘_download_url_to_file’ from 'torch.utils.model_zoo

因为我安装的版本中只有download_url_to_file,把报错的地方_download_url_to_file都改为download_url_to_file


2.6 error: OpenCV(4.7.0) : -1: error: (-5:Bad argument) infunction 'putText

在这里插入图片描述
这里是opencv-python版本引起的问题,自己下载一个和python对应的版本安装

https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/opencv-python/

pip uninstall opencv-python
pip install opencv_python-3.4.7.28-cp37-cp37m-manylinux1_x86_64.whl

2.7 No module named ‘cityscapesscripts’

pip install cityscapesscripts

最终结果
在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值