安装pytorch
参考:https://blog.csdn.net/Guoyingyuan/article/details/124497041
Anaconda promot(在Anaconda promot窗口内执行)
(1)
python -m pip install -U pip
conda create --name pytorch3.7 python=3.7
Anaconda promot
在这里找需要版本的pytorch安装命令,带CUDA即为GPU版本
https://pytorch.org/get-started/previous-versions/
https://pytorch.org/get-started/locally/
(2)
activate pytorch3.7
# CUDA 11.3
(torch1.12.1)
conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.3 -c pytorch
(torch1.11.0)
conda install pytorch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0 cudatoolkit=11.3 -c pytorch
Anaconda promot
(3)安装sklearn库
activate tensorflow
pip install scikit-learn
出现乱码的解决方法
(4)安装cpu版本
conda install pytorch==1.8.1 torchvision==0.9.1 torchaudio==0.8.1 cpuonly -c pytorch
出现错误:assertionerror: torch not compiled with cuda enabled ( Solution )
解决方案1:从CUDA切换到CPU版本 –
通常在PyTorch中编译任何神经网络时,我们可以通过 cuda 启用。如果我们简单地删除相同的内容,就会消除错误。请参阅下面的示例,如果您使用类似的语法模式,则在编译神经网络时删除 Cuda。
1.将代码中指定设备的代码改为cpu
####这里用来表明torch的版本,cpu或者cuda
device = "cpu"
2.将引用cuda的函数修改
from torch import nn
net = nn.Sequential(
nn.Linear(18*18, 80),
nn.ReLU(),
nn.Linear(80, 80),
nn.ReLU(),
nn.Linear(80, 10),
nn.LogSoftmax()
).cuda()
正确的做法是——
断言错误 torch 未使用启用 cuda 的解决方案进行编译