linux上部署torch(CPU/GPU)
linux上部署的pytorch和python的版本和cuda的版本有关系。因此在安装pytorch需要根据自己系统上的部署的cuda和python版本来部署pytorch。一、部署pytorchpytor的官网如下https://pytorch.org/get-started/locally/在官网中根据自己的环境安装pytorch,因为我系统上没有安装Anaconda因此需安装来源选择...
·
linux上部署的pytorch和python的版本和cuda的版本有关系。因此在安装pytorch需要根据自己系统上的部署的cuda和python版本来部署pytorch。
注意:使用pip
或pip3
安装时要注意其对应的是哪个版本的python
查看方式为:pip -V
一、部署pytorch(CPU/GPU)
1、部署pytorch(GPU)版
pytor的官网如下
https://pytorch.org/get-started/locally/
在官网中根据自己的环境安装pytorch,因为我系统上没有安装Anaconda因此需安装来源选择使用pip安装。
如上图所示,系统自带python2和python3版本,在python3上安装时需要安装python-pip3
sudo apt-get install python3-pip
注意:安装过程中要按住两个文件。
pip3 install https://download.pytorch.org/whl/cu100/torch-1.1.0-cp35-cp35m-linux_x86_64.whl
pip3 install https://download.pytorch.org/whl/cu100/torchvision-0.3.0-cp35-cp35m-linux_x86_64.whl
2、部署pytorch的CPU版
注意:安装过程中要按住两个文件。
pip3 install https://download.pytorch.org/whl/cpu/torch-1.1.0-cp36-cp36m-linux_x86_64.whl
pip3 install https://download.pytorch.org/whl/cpu/torchvision-0.3.0-cp36-cp36m-linux_x86_64.whl
二、查看python和CUDA版本
安装完成之后重新检查一下是否安装在python3环境下,以及是否和cuda版本想对应。
查看python
python\python3 或 python -V | python3 -V
查看cuda版本
nvcc -V
三、验证是否安装pytorch完成
python3
import pytorch
import torchvison
发现在import torchvision
时出现以下错误:
Detected that PyTorch and torchvision were compiled with different CUDA versions. PyTorch has CUDA Version=9.0 and torchvision has CUDA Version=10.0. Please reinstall the torchvision that matches your PyTorch install.
解决办法:
pip3 install --no-deps torchvision
重新验证torchvision
:
完美解决。
最后,验证GPU是否可用
返回True,表明已经可以使用GPU了!
更多推荐
已为社区贡献4条内容
所有评论(0)