Download and use torchvision dataset without internet connection

Viewed 225

I am new to pytorch and would like to run some examples on a computer without internet connection.

In the tutorial page the following code is given for a computer with internet connection. I would appreciate it if someone could advise on how to do the same for a computer with no internet connection.

import torch
from torch import nn
from torch.utils.data import DataLoader
from torchvision import datasets
from torchvision.transforms import ToTensor, Lambda

training_data = datasets.FashionMNIST(
    root="data",
    train=True,
    download=True,
    transform=ToTensor()
)

test_data = datasets.FashionMNIST(
    root="data",
    train=False,
    download=True,
    transform=ToTensor()
)
1 Answers

First you have to download the dataset from a computer that has internet connection, and then copy it to the one that has torch. I will explain the steps:

(A) Download the following files in the links below :

http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-images-idx3-ubyte.gz

http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-labels-idx1-ubyte.gz

http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-images-idx3-ubyte.gz

http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-labels-idx1-ubyte.gz

(B) Copy these files to torch ready PC under torch/datasets/FashionMNIST/raw/

(C) Extract them using: gzip -d *.gz

(D) Change your code to point to the dataset location

training_data = datasets.FashionMNIST(
    root="torch/datasets/",
    train=True,
    download=True,
    transform=ToTensor()
)

test_data = datasets.FashionMNIST(
    root="torch/datasets/",
    train=False,
    download=True,
    transform=ToTensor()
)
Related