文章作者:Tyan
博客:noahsnail.com | CSDN | 简书
本文主要是关于PyTorch的一些用法。
1 | import torch |
torch.Size([60000, 28, 28])
torch.Size([60000])
torch.Size([10000, 28, 28])
torch.Size([10000])
1 | # 查看图像 |
1 | # 数据加载 |
CNN (
(conv1): Sequential (
(0): Conv2d(1, 16, kernel_size=(5, 5), stride=(1, 1), padding=(2, 2))
(1): ReLU ()
(2): MaxPool2d (size=(2, 2), stride=(2, 2), dilation=(1, 1))
)
(conv2): Sequential (
(0): Conv2d(16, 32, kernel_size=(5, 5), stride=(1, 1), padding=(2, 2))
(1): ReLU ()
(2): MaxPool2d (size=(2, 2), stride=(2, 2), dilation=(1, 1))
)
(output): Linear (1568 -> 10)
)
1 | # 定义优化器 |
Epoch: 0 | train loss: 2.2787 | accuracy: 0.0982
Epoch: 0 | train loss: 0.0788 | accuracy: 0.9592
Epoch: 0 | train loss: 0.0587 | accuracy: 0.9626
Epoch: 0 | train loss: 0.0188 | accuracy: 0.9745
Epoch: 0 | train loss: 0.0707 | accuracy: 0.9759
Epoch: 0 | train loss: 0.0564 | accuracy: 0.9775
Epoch: 0 | train loss: 0.0489 | accuracy: 0.9779
Epoch: 0 | train loss: 0.0925 | accuracy: 0.9791
Epoch: 0 | train loss: 0.0566 | accuracy: 0.9834