ubuntu18.04下pytorch版Maskrcnn编译错误汇总
- 1 anconda环境配置
- 2 bug及解决办法
- 2.1 Detected CUDA version (11.2) mismatches the version that was used to compile PyTorch(10.2)
- 2.2 error: legacy-install-failure × Encountered error while trying to install package.╰─> apex
- 2.3 ModuleNotFoundError: No module named 'xxx'
- 2.4 module 'torch._six' has no attribute 'PY37'
- 2.5 cannot import name '_download_url_to_file' from 'torch.utils.model_zoo
- 2.6 error: OpenCV(4.7.0) : -1: error: (-5:Bad argument) infunction 'putText
搞了一整天,终于把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 ./
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
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
最终结果