Skip to content

Commit 0d43d52

Browse files
committed
download
1 parent d67206c commit 0d43d52

File tree

6 files changed

+32
-13
lines changed

6 files changed

+32
-13
lines changed

pl_examples/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
from urllib.error import HTTPError
23

34
from six.moves import urllib
45

@@ -14,8 +15,16 @@
1415
_DATASETS_PATH = os.path.join(_PACKAGE_ROOT, 'Datasets')
1516

1617
_TORCHVISION_AVAILABLE = _module_available("torchvision")
18+
_TORCHVISION_MNIST_AVAILABLE = True
1719
_DALI_AVAILABLE = _module_available("nvidia.dali")
1820

21+
if _TORCHVISION_AVAILABLE:
22+
try:
23+
from torchvision.datasets.mnist import MNIST
24+
MNIST(_DATASETS_PATH, download=True)
25+
except HTTPError:
26+
_TORCHVISION_MNIST_AVAILABLE = False
27+
1928
LIGHTNING_LOGO = """
2029
####
2130
###########

pl_examples/basic_examples/autoencoder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
from torch.utils.data import DataLoader, random_split
2121

2222
import pytorch_lightning as pl
23-
from pl_examples import _DATASETS_PATH, _TORCHVISION_AVAILABLE, cli_lightning_logo
23+
from pl_examples import _DATASETS_PATH, _TORCHVISION_AVAILABLE, _TORCHVISION_MNIST_AVAILABLE, cli_lightning_logo
2424

25-
if _TORCHVISION_AVAILABLE:
25+
if _TORCHVISION_AVAILABLE and _TORCHVISION_MNIST_AVAILABLE:
2626
from torchvision import transforms
2727
from torchvision.datasets.mnist import MNIST
2828
else:

pl_examples/basic_examples/backbone_image_classifier.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
from torch.utils.data import DataLoader, random_split
2020

2121
import pytorch_lightning as pl
22-
from pl_examples import _DATASETS_PATH, _TORCHVISION_AVAILABLE, cli_lightning_logo
22+
from pl_examples import _DATASETS_PATH, _TORCHVISION_AVAILABLE, _TORCHVISION_MNIST_AVAILABLE, cli_lightning_logo
2323

24-
if _TORCHVISION_AVAILABLE:
24+
if _TORCHVISION_AVAILABLE and _TORCHVISION_MNIST_AVAILABLE:
2525
from torchvision import transforms
2626
from torchvision.datasets.mnist import MNIST
2727
else:

pl_examples/basic_examples/dali_image_classifier.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,15 @@
2323
from torch.utils.data import random_split
2424

2525
import pytorch_lightning as pl
26-
from pl_examples import _DALI_AVAILABLE, _DATASETS_PATH, _TORCHVISION_AVAILABLE, cli_lightning_logo
27-
28-
if _TORCHVISION_AVAILABLE:
26+
from pl_examples import (
27+
_DALI_AVAILABLE,
28+
_DATASETS_PATH,
29+
_TORCHVISION_AVAILABLE,
30+
_TORCHVISION_MNIST_AVAILABLE,
31+
cli_lightning_logo,
32+
)
33+
34+
if _TORCHVISION_AVAILABLE and _TORCHVISION_MNIST_AVAILABLE:
2935
from torchvision import transforms
3036
from torchvision.datasets.mnist import MNIST
3137
else:

pl_examples/basic_examples/mnist_datamodule.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
from torch.utils.data import DataLoader, random_split
1919

20-
from pl_examples import _DATASETS_PATH, _TORCHVISION_AVAILABLE
20+
from pl_examples import _DATASETS_PATH, _TORCHVISION_AVAILABLE, _TORCHVISION_MNIST_AVAILABLE
2121
from pytorch_lightning import LightningDataModule
2222

23-
if _TORCHVISION_AVAILABLE:
23+
if _TORCHVISION_AVAILABLE and _TORCHVISION_MNIST_AVAILABLE:
2424
from torchvision import transforms as transform_lib
2525
from torchvision.datasets import MNIST
2626
else:

pl_examples/domain_templates/generative_adversarial_net.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,19 @@
2626
import torch
2727
import torch.nn as nn
2828
import torch.nn.functional as F # noqa
29-
import torchvision
30-
import torchvision.transforms as transforms
3129
from torch.utils.data import DataLoader
32-
from torchvision.datasets import MNIST
3330

34-
from pl_examples import cli_lightning_logo
31+
from pl_examples import _TORCHVISION_AVAILABLE, _TORCHVISION_MNIST_AVAILABLE, cli_lightning_logo
3532
from pytorch_lightning.core import LightningDataModule, LightningModule
3633
from pytorch_lightning.trainer import Trainer
3734

35+
if _TORCHVISION_AVAILABLE and _TORCHVISION_MNIST_AVAILABLE:
36+
import torchvision
37+
import torchvision.transforms as transforms
38+
from torchvision.datasets import MNIST
39+
else:
40+
from tests.helpers.datasets import MNIST
41+
3842

3943
class Generator(nn.Module):
4044
"""

0 commit comments

Comments
 (0)