pytorch / pytorch/vision

torchvision data downloader aborts if ipywidgets are not available

Open
#3,284 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

dependency issue module: datasets
Dominant language
Python
Stars
17.9k
Forks
7.3k
Avg merge
1d 15h
Merged PRs (30d)
13

Description

🐛 Bug

I am testing some PyTorch code in Deepnote and the following call to torchvision aborts since the environment doesn't support ipywidgets

test_data = torchvision.datasets.MNIST('../data', train=False, download=True, transform=local_transforms)

To Reproduce

Check the following notebook - https://deepnote.com/project/0b12c588-a1de-4d66-bb0f-fa6b8f9b1b87

ImportError: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-3-c62d245b04eb> in <module>
      5 local_transforms = torchvision.transforms.Compose([local_transform_1, local_transform_2])
      6 
----> 7 test_data = torchvision.datasets.MNIST('../data', train=False, download=True, transform=local_transforms)

/shared-libs/python3.7/py/lib/python3.7/site-packages/torchvision/datasets/mnist.py in __init__(self, root, train, transform, target_transform, download)
     77 
     78         if download:
---> 79             self.download()
     80 
     81         if not self._check_exists():

/shared-libs/python3.7/py/lib/python3.7/site-packages/torchvision/datasets/mnist.py in download(self)
    144         for url, md5 in self.resources:
    145             filename = url.rpartition('/')[2]
--> 146             download_and_extract_archive(url, download_root=self.raw_folder, filename=filename, md5=md5)
    147 
    148         # process and save as torch files

/shared-libs/python3.7/py/lib/python3.7/site-packages/torchvision/datasets/utils.py in download_and_extract_archive(url, download_root, extract_root, filename, md5, remove_finished)
    254         filename = os.path.basename(url)
    255 
--> 256     download_url(url, download_root, filename, md5)
    257 
    258     archive = os.path.join(download_root, filename)

/shared-libs/python3.7/py/lib/python3.7/site-packages/torchvision/datasets/utils.py in download_url(url, root, filename, md5)
     70             urllib.request.urlretrieve(
     71                 url, fpath,
---> 72                 reporthook=gen_bar_updater()
     73             )
     74         except (urllib.error.URLError, IOError) as e:  # type: ignore[attr-defined]

/shared-libs/python3.7/py/lib/python3.7/site-packages/torchvision/datasets/utils.py in gen_bar_updater()
     13 
     14 def gen_bar_updater() -> Callable[[int, int, int], None]:
---> 15     pbar = tqdm(total=None)
     16 
     17     def bar_update(count, block_size, total_size):

/shared-libs/python3.7/py/lib/python3.7/site-packages/tqdm/notebook.py in __init__(self, *args, **kwargs)
    246         unit_scale = 1 if self.unit_scale is True else self.unit_scale or 1
    247         total = self.total * unit_scale if self.total else self.total
--> 248         self.container = self.status_printer(self.fp, total, self.desc, self.ncols)
    249         self.container.pbar = self
    250         if display_here:

/shared-libs/python3.7/py/lib/python3.7/site-packages/tqdm/notebook.py in status_printer(_, total, desc, ncols)
    113         if IProgress is None:  # #187 #451 #558 #872
    114             raise ImportError(
--> 115                 "IProgress not found. Please update jupyter and ipywidgets."
    116                 " See https://ipywidgets.readthedocs.io/en/stable"
    117                 "/user_install.html")

ImportError: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html

Expected behavior

Maybe a check can be added that skips call to tqdm if it's not available?

cc @pmeier

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in torchvision/datasets/utils.py, following download_url into gen_bar_updater, and reproduce the MNIST download in an environment without ipywidgets. The fix is done when downloading does not raise the IProgress ImportError and still completes with an available progress or fallback path.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
computer-vision, machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.