今天不小心將conda環(huán)境中的一個pytorch環(huán)境中的torch包給搞混了,將其更新了一下,發(fā)生了一些問題:
當時運行了一下這個代碼:?pip install torchvision --upgrade
導致了環(huán)境中包的混亂:
只能說欲哭無淚,當時這個?pytorch環(huán)境中我是安裝的CUDA11.8的版本應該,后來安裝了cpu版本的將原先的給覆蓋了,導致運行代碼時遇到如下報錯:
ValueError: Could not find the operator torchvision::nms. Please make sure you have already registered the operator and (if registered from C++) loaded it via torch.ops.load_library.
遇到“Could not find the operator torchvision::nms”這類錯誤,通常是因為torch
和torchvision
版本之間的不兼容問題。您提供的信息顯示,您的torch
版本是2.1.2+cu118
。這個問題可能因為torchvision
版本不匹配或者安裝有問題導致。
這次無意的更新導致了版本的沖突問題?。。?/h3>
只能重新安裝一遍了,先查看顯卡配置:
nvidia-smi
?我的CUDA Version:12.1
前往Pytorch官網進行安裝:Start Locally | PyTorch
復制這個安裝命令:
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
在pycharm的終端處可以進行安裝,輸入如下指令:
conda activate pytorch
?pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
安裝時間比較長,耐心等待。。。。。。。
安裝結束后,查看torch與torchvision的cuda版本:
pip show torch torchvision
驗證安裝
安裝完成后,您可以通過運行以下Python代碼來驗證torchvision
是否正確安裝,并且是否能夠與torch
一起使用CUDA:
import torch
import torchvision
print("Torch version:", torch.__version__)
print("Torchvision version:", torchvision.__version__)
print("CUDA available:", torch.cuda.is_available())
if torch.cuda.is_available():
print("CUDA version:", torch.version.cuda)
我的測試結果:
說明安裝成功?。。?/p>
?最后測試一下代碼運行:文章來源:http://www.zghlxwxcb.cn/news/detail-828676.html
沒有報錯,又可以繼續(xù)學習Pytorch了?。?!?文章來源地址http://www.zghlxwxcb.cn/news/detail-828676.html
到了這里,關于深度學習:Pytorch安裝的torch與torchvision的cuda版本沖突問題與解決歷程記錄的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!