错误提示是 torchvision和torch的版本不兼容
File "D:\Programs\conda411\envs\envZhao\lib\site-packages\torchvision\extension.py", line 32, in _assert_has_ops
"Couldn't load custom C++ ops. This can happen if your PyTorch and "
RuntimeError: Couldn't load custom C++ ops. This can happen if your PyTorch and torchvision versions are incompatible, or if you had errors while compiling torchvision from source. For further information on the compatible versions, check https://github.com/pytorch/vision#installation for the compatibility matrix. Please check your PyTorch version with torch.__version__ and your torchvision version with torchvision.__version__ and verify if they are compatible, and if not please reinstall torchvision so that it matches your PyTorch install.
之前安装采用的国内conda源源,安装的版本是:
torchvison 0.11.3
pytorch 1.10.2
删除国内源,采用默认的conda源,
conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
会更新下载:torchvison 0.12.0
pytorch 1.11.0
国外的源下载的慢,用国内的源尝试:
添加清华源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
用如下conda命令安装pytorch
conda install pytorch torchvision torchaudio cudatoolkit=11.3
安装上了最新版本的pytorch和torchvision,
torchvison 0.12.0
pytorch 1.11.0
但是又出现**AttributeError: ‘Upsample’ object has no attribute ‘recompute_scale_factor’**错误,具体如下:
D:\Programs\conda411\envs\envZhao\python.exe D:/coding/python3/yolov5-6.1/detect.py
detect: weights=yolov5s.pt, source=data\images, data=data\coco128.yaml, imgsz=[640, 640], conf_thres=0.25, iou_thres=0.45, max_det=1000, device=, view_img=False, save_txt=False, save_conf=False, save_crop=False, nosave=False, classes=None, agnostic_nms=False, augment=False, visualize=False, update=False, project=runs\detect, name=exp, exist_ok=False, line_thickness=3, hide_labels=False, hide_conf=False, half=False, dnn=False
YOLOv5 2022-4-25 torch 1.11.0 CPU
Fusing layers...
Model Summary: 213 layers, 7225885 parameters, 0 gradients
Traceback (most recent call last):
File "D:/coding/python3/yolov5-6.1/detect.py", line 257, in
main(opt)
File "D:/coding/python3/yolov5-6.1/detect.py", line 252, in main
run(**vars(opt))
File "D:\Programs\conda411\envs\envZhao\lib\site-packages\torch\autograd\grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "D:/coding/python3/yolov5-6.1/detect.py", line 127, in run
pred = model(im, augment=augment, visualize=visualize)
File "D:\Programs\conda411\envs\envZhao\lib\site-packages\torch\nn\modules\module.py", line 1110, in _call_impl
return forward_call(*input, **kwargs)
File "D:\coding\python3\yolov5-6.1\models\common.py", line 402, in forward
y = self.model(im) if self.jit else self.model(im, augment=augment, visualize=visualize)
File "D:\Programs\conda411\envs\envZhao\lib\site-packages\torch\nn\modules\module.py", line 1110, in _call_impl
return forward_call(*input, **kwargs)
File "D:\coding\python3\yolov5-6.1\models\yolo.py", line 126, in forward
return self._forward_once(x, profile, visualize) # single-scale inference, train
File "D:\coding\python3\yolov5-6.1\models\yolo.py", line 149, in _forward_once
x = m(x) # run
File "D:\Programs\conda411\envs\envZhao\lib\site-packages\torch\nn\modules\module.py", line 1110, in _call_impl
return forward_call(*input, **kwargs)
File "D:\Programs\conda411\envs\envZhao\lib\site-packages\torch\nn\modules\upsampling.py", line 154, in forward
recompute_scale_factor=self.recompute_scale_factor)
File "D:\Programs\conda411\envs\envZhao\lib\site-packages\torch\nn\modules\module.py", line 1186, in __getattr__
type(self).__name__, name))
AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor'
Process finished with exit code 1
根据网上的建议,应该降低PyTorch的版本到1.9.0
# CUDA 10.2
conda install pytorch==1.9.0 torchvision==0.10.0 torchaudio==0.9.0 cudatoolkit=10.2 -c pytorch
# CUDA 11.3
conda install pytorch==1.9.0 torchvision==0.10.0 torchaudio==0.9.0 cudatoolkit=11.3 -c pytorch -c conda-forge
# CPU Only
conda install pytorch==1.9.0 torchvision==0.10.0 torchaudio==0.9.0 cpuonly -c pytorch
因为pillow的原因,这个torchvision再次安装,
利用pip
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)