How to call and train MNIST Dataset?

Ra_Concilio: <p>How do direct to the local root and/or online root for MNIST dataset to train and transform it? I downloaded MNIST onto my harddrive here: <a href="https://www.kaggle.com/datasets/novinnouri/mnist-dataset?resource=download" class="inline-onebox" rel="noopener nofollow ugc">MNIST_dataset | Kaggle</a></p>
<p>I tried this but it is getting an error?<br>
train_data =datasets.MNIST(<br>
root = ‘data’,<br>
train = True,<br>
transform = ToTensor(),<br>
download = True<br>
)</p>

ptrblck: <p>Point the <code>root</code> argument to the location where your MNIST dataset is stored and use <code>download=False</code>.</p>

Ra_Concilio: <p>How do I do that with code?</p>

foti: <pre><code class="lang-auto">mnist_root = your/mnist/path
train_data = datasets.MNIST(
root = mnist_root,
train = True,
transform = ToTensor(),
download = False
)
</code></pre>

Eduardo_Lawson: <p>If you are using Linux, navigate through the terminal to the folder where the data is stored and run <code>pwd</code>. The path will be returned, just copy that and paste in root=’ '.<br>
Or you can move the folder to the directory you are working and create the folder “data” and move it in.</p>

Ra_Concilio: <p><a class="mention" href="/u/foti">@foti</a>  and <a class="mention" href="/u/eduardo_lawson">@Eduardo_Lawson</a> - I am using Windows.</p>
<p>Perhaps the issue is the file structure? I have tried every combination of zip files, test, train data, etc. and also root folders. Should the MNIST data be in a zip file?</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/3/0/308be214fe516e34c8046196978cbe20235ed951.png" data-download-href="https://discuss.pytorch.org/uploads/default/308be214fe516e34c8046196978cbe20235ed951" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/3/0/308be214fe516e34c8046196978cbe20235ed951_2_411x500.png" alt="image" data-base62-sha1="6VsCf1rmr90XIhwvXc5Kx9cxnxv" width="411" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/3/0/308be214fe516e34c8046196978cbe20235ed951_2_411x500.png, https://discuss.pytorch.org/uploads/default/optimized/3X/3/0/308be214fe516e34c8046196978cbe20235ed951_2_616x750.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/3/0/308be214fe516e34c8046196978cbe20235ed951_2_822x1000.png 2x" data-dominant-color="FCFCFC"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">2259×2748 243 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

ptrblck: <p>Just download the dataset via <code>download=True</code>, as already mentioned, and check the structure:</p>
<pre data-code-wrap="python"><code class="lang-python">import torch
import torchvision.datasets as datasets

dataset = datasets.MNIST(
        root="./",
        train=True,
        download=True,
)
</code></pre>
<pre data-code-wrap="python"><code class="lang-python">tree 
.
├── MNIST
│   └── raw
│       ├── t10k-images-idx3-ubyte
│       ├── t10k-images-idx3-ubyte.gz
│       ├── t10k-labels-idx1-ubyte
│       ├── t10k-labels-idx1-ubyte.gz
│       ├── train-images-idx3-ubyte
│       ├── train-images-idx3-ubyte.gz
│       ├── train-labels-idx1-ubyte
│       └── train-labels-idx1-ubyte.gz
└── tmp.py
</code></pre>
<p>I don’t know why you want to download the dataset manually instead of letting <code>datasets.MNIST</code> do it.</p>

Ra_Concilio: <p><a class="mention" href="/u/ptrblck">@ptrblck</a> When I try to do it straight as datasets.MNIST it throws an error. When I check the MNIST.py file, it points to a URL where there is no data set. I am not sure where to get these files that you have in your raw folder. I only have the images in folders marked 0-10. Where can I download these?</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/5/a/5a19150fe9b3532b7c2044a8713bfe39296fb13a.png" data-download-href="https://discuss.pytorch.org/uploads/default/5a19150fe9b3532b7c2044a8713bfe39296fb13a" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/5/a/5a19150fe9b3532b7c2044a8713bfe39296fb13a_2_690x448.png" alt="image" data-base62-sha1="cR2I4yYqsqGhC7bhiBXLSH0v7XI" width="690" height="448" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/5/a/5a19150fe9b3532b7c2044a8713bfe39296fb13a_2_690x448.png, https://discuss.pytorch.org/uploads/default/optimized/3X/5/a/5a19150fe9b3532b7c2044a8713bfe39296fb13a_2_1035x672.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/5/a/5a19150fe9b3532b7c2044a8713bfe39296fb13a_2_1380x896.png 2x" data-dominant-color="242726"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1623×1055 113 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

ptrblck: <p>I cannot reproduce the issue and am able to re-download the dataset on different systems and networks.</p>

Ra_Concilio: <p><a class="mention" href="/u/ptrblck">@ptrblck</a> - Can I see your MNIST.py file? Which URL does it point to? Note, I did not know where to manually download the files from so I have not. Where did you get those files?</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/c/4/c4d414b18a7c679b887c720366977f377e5a96e6.png" data-download-href="https://discuss.pytorch.org/uploads/default/c4d414b18a7c679b887c720366977f377e5a96e6" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/c/4/c4d414b18a7c679b887c720366977f377e5a96e6_2_690x396.png" alt="image" data-base62-sha1="s5dXQBSlAEkLMBQuTo76YC5wrwG" width="690" height="396" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/c/4/c4d414b18a7c679b887c720366977f377e5a96e6_2_690x396.png, https://discuss.pytorch.org/uploads/default/optimized/3X/c/4/c4d414b18a7c679b887c720366977f377e5a96e6_2_1035x594.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/c/4/c4d414b18a7c679b887c720366977f377e5a96e6_2_1380x792.png 2x" data-dominant-color="202222"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">2724×1567 271 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

Ra_Concilio: <aside class="quote no-group" data-username="ptrblck" data-post="7" data-topic="219117">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/48/1823_2.png" class="avatar"> ptrblck:</div>
<blockquote>
<p><code>t10k-images-idx3-ubyte</code></p>
</blockquote>
</aside>
<p>How did you download the dataset?</p>