Learn practical skills, build real-world projects, and advance your career
Created 3 years ago
!pip install numpy matplotlib torch==1.7.0+cpu torchvision==0.8.1+cpu torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html
Looking in links: https://download.pytorch.org/whl/torch_stable.html
Requirement already satisfied: numpy in c:\users\admin\anaconda\lib\site-packages (1.18.5)
Requirement already satisfied: matplotlib in c:\users\admin\anaconda\lib\site-packages (3.2.2)
Requirement already satisfied: torch==1.7.0+cpu in c:\users\admin\anaconda\lib\site-packages (1.7.0+cpu)
Requirement already satisfied: torchvision==0.8.1+cpu in c:\users\admin\anaconda\lib\site-packages (0.8.1+cpu)
Requirement already satisfied: torchaudio==0.7.0 in c:\users\admin\anaconda\lib\site-packages (0.7.0)
Requirement already satisfied: python-dateutil>=2.1 in c:\users\admin\anaconda\lib\site-packages (from matplotlib) (2.8.1)
Requirement already satisfied: kiwisolver>=1.0.1 in c:\users\admin\anaconda\lib\site-packages (from matplotlib) (1.2.0)
Requirement already satisfied: cycler>=0.10 in c:\users\admin\anaconda\lib\site-packages (from matplotlib) (0.10.0)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in c:\users\admin\anaconda\lib\site-packages (from matplotlib) (2.4.7)
Requirement already satisfied: typing-extensions in c:\users\admin\anaconda\lib\site-packages (from torch==1.7.0+cpu) (3.7.4.2)
Requirement already satisfied: dataclasses in c:\users\admin\anaconda\lib\site-packages (from torch==1.7.0+cpu) (0.6)
Requirement already satisfied: future in c:\users\admin\anaconda\lib\site-packages (from torch==1.7.0+cpu) (0.18.2)
Requirement already satisfied: pillow>=4.1.1 in c:\users\admin\anaconda\lib\site-packages (from torchvision==0.8.1+cpu) (7.2.0)
Requirement already satisfied: six>=1.5 in c:\users\admin\anaconda\lib\site-packages (from python-dateutil>=2.1->matplotlib) (1.15.0)
import torch
import torchvision
from torchvision.datasets import MNIST
# Download the training dataset
datasets = MNIST(root = 'data/', download = True)
Downloading http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz to data/MNIST\raw\train-images-idx3-ubyte.gz
HBox(children=(FloatProgress(value=1.0, bar_style='info', max=1.0), HTML(value='')))
Extracting data/MNIST\raw\train-images-idx3-ubyte.gz to data/MNIST\raw
Downloading http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz to data/MNIST\raw\train-labels-idx1-ubyte.gz
HBox(children=(FloatProgress(value=1.0, bar_style='info', max=1.0), HTML(value='')))
Extracting data/MNIST\raw\train-labels-idx1-ubyte.gz to data/MNIST\raw
Downloading http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz to data/MNIST\raw\t10k-images-idx3-ubyte.gz
HBox(children=(FloatProgress(value=1.0, bar_style='info', max=1.0), HTML(value='')))
Extracting data/MNIST\raw\t10k-images-idx3-ubyte.gz to data/MNIST\raw
Downloading http://yann.lecun.com/exdb/mnist/t10k-labels-idx1-ubyte.gz to data/MNIST\raw\t10k-labels-idx1-ubyte.gz
HBox(children=(FloatProgress(value=1.0, bar_style='info', max=1.0), HTML(value='')))
Extracting data/MNIST\raw\t10k-labels-idx1-ubyte.gz to data/MNIST\raw
Processing...
Done!
C:\Users\ADMIN\anaconda\lib\site-packages\torchvision\datasets\mnist.py:480: 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:141.)
return torch.from_numpy(parsed.astype(m[2], copy=False)).view(*s)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-3-672e55d35974> in <module>
1 # Download the training dataset
2 datasets = MNIST(root = 'data/', download = True)
----> 3 datasets.shape()
AttributeError: 'MNIST' object has no attribute 'shape'
len(datasets)
60000
# Load the test dataset
test_dataset = MNIST(root = 'data/', train=False)
test_dataset
Dataset MNIST
Number of datapoints: 10000
Root location: data/
Split: Test