运行结果
(pytorch) appledeMacBook-Pro:pytorch apple$ python3 learn1.py /opt/miniconda3/envs/pytorch/lib/python3.7/site-packages/torchvision/datasets/mnist.py:498: UserWarning: The given NumPy array is not writeable, and PyTorch does not support non-writeable tensors. This means you can write to the underlying (supposedly non-writeable) NumPy array using the tensor. You may want to copy the array to protect its data or make it writeable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at ../torch/csrc/utils/tensor_numpy.cpp:180.) return torch.from_numpy(parsed.astype(m[2], copy False)).view(*s) Shape of X [N, C, H, W]: torch.Size([64, 1, 28, 28]) Shape of y: torch.Size([64]) torch.int64 Using cpu device NeuralNetwork( (flatten): Flatten(start_dim 1, end_dim -1) (linear_relu_stack): Sequential( (0): Linear(in_features 784, out_features 512, bias True) (1): ReLU() (2): Linear(in_features 512, out_features 512, bias True) (3): ReLU() (4): Linear(in_features 512, out_features 10, bias True) Epoch 1 ------------------------------- loss: 2.314974 [ 0/60000] loss: 2.301318 [ 6400/60000] loss: 2.279395 [12800/60000] loss: 2.260673 [19200/60000] loss: 2.256194 [25600/60000] loss: 2.230177 [32000/60000] loss: 2.232735 [38400/60000] loss: 2.197281 [44800/60000] loss: 2.199913 [51200/60000] loss: 2.165345 [57600/60000] Test Error: Accuracy: 46.0%, Avg loss: 2.161378 Epoch 2 ------------------------------- loss: 2.181149 [ 0/60000] loss: 2.164842 [ 6400/60000] loss: 2.110326 [12800/60000] loss: 2.114110 [19200/60000] loss: 2.074363 [25600/60000] loss: 2.027263 [32000/60000] loss: 2.043373 [38400/60000] loss: 1.965748 [44800/60000] loss: 1.974563 [51200/60000] loss: 1.901750 [57600/60000] Test Error: Accuracy: 58.3%, Avg loss: 1.897587 Epoch 3 ------------------------------- loss: 1.938917 [ 0/60000] loss: 1.899398 [ 6400/60000] loss: 1.785908 [12800/60000] loss: 1.814409 [19200/60000] loss: 1.720331 [25600/60000] loss: 1.681701 [32000/60000] loss: 1.687258 [38400/60000] loss: 1.586764 [44800/60000] loss: 1.616351 [51200/60000] loss: 1.508570 [57600/60000] Test Error: Accuracy: 60.8%, Avg loss: 1.523732 Epoch 4 ------------------------------- loss: 1.598114 [ 0/60000] loss: 1.553433 [ 6400/60000] loss: 1.402492 [12800/60000] loss: 1.467502 [19200/60000] loss: 1.366623 [25600/60000] loss: 1.368079 [32000/60000] loss: 1.371022 [38400/60000] loss: 1.290068 [44800/60000] loss: 1.333592 [51200/60000] loss: 1.231188 [57600/60000] Test Error: Accuracy: 62.9%, Avg loss: 1.253851 Epoch 5 ------------------------------- loss: 1.339722 [ 0/60000] loss: 1.310711 [ 6400/60000] loss: 1.143826 [12800/60000] loss: 1.242881 [19200/60000] loss: 1.134900 [25600/60000] loss: 1.168011 [32000/60000] loss: 1.180709 [38400/60000] loss: 1.111995 [44800/60000] loss: 1.158805 [51200/60000] loss: 1.070515 [57600/60000] Test Error: Accuracy: 64.0%, Avg loss: 1.088987 Done! Saved PyTorch Model State to model.pth Predicted: Ankle boot , Actual: Ankle boot



