win10下安裝pytorch1.5

參考博文

https://blog.csdn.net/JohnLeeK/article/details/106387864

https://blog.csdn.net/weixin_45092662/article/details/105927948

 

一、確保已經安裝了 anaconda和cuda

安裝anaconda,python,pycharm,cuda的參考博文

如何查看已經安裝的cuda版本:

開始菜單->Anaconda3—>Anaconda Prompt,輸入指令:nvidia-smi    按回車,運行如下,表明我的電腦上安裝的是cuda10.1的版本。

二、pytorch官網

https://pytorch.org/  可惜無法訪問

 

三、安裝步驟

1、開始菜單->Anaconda3—>Anaconda Prompt,輸入指令:conda install pytorch torchvision cudatoolkit=10.1 -c pytorch

打印出如下所示的信息。

2、選擇,yes

出現了下載失敗的問題

3、上面的報錯是下載失敗導致的。正如提示,簡單的再試一下,或許就可以了。

四、pytorch測試

1、開始菜單->Anaconda3—>Anaconda Prompt  輸入:python。進入python環境。

2、輸入:import porch。如果沒有報錯,就表示安裝成功。

3、pycharm中運行代碼,有輸出,表明安裝ok

import torch
import torch.nn as nn
import torch.nn.functional as F


class Net(nn.Module):

    def __init__(self):
        super(Net, self).__init__()
        # 1 input image channel, 6 output channels, 5x5 square convolution
        # kernel
        self.conv1 = nn.Conv2d(1, 6, 5)
        self.conv2 = nn.Conv2d(6, 16, 5)
        # an affine operation: y = Wx + b
        self.fc1 = nn.Linear(16 * 5 * 5, 120)
        self.fc2 = nn.Linear(120, 84)
        self.fc3 = nn.Linear(84, 10)

    def forward(self, x):
        # Max pooling over a (2, 2) window
        x = F.max_pool2d(F.relu(self.conv1(x)), (2, 2))
        # If the size is a square you can only specify a single number
        x = F.max_pool2d(F.relu(self.conv2(x)), 2)
        x = x.view(-1, self.num_flat_features(x))
        x = F.relu(self.fc1(x))
        x = F.relu(self.fc2(x))
        x = self.fc3(x)
        return x

    def num_flat_features(self, x):
        size = x.size()[1:]  # all dimensions except the batch dimension
        num_features = 1
        for s in size:
            num_features *= s
        return num_features


net = Net()
print(net)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章