Skip to content

Commit

Permalink
Progress Bar for download_url (#497)
Browse files Browse the repository at this point in the history
* Added Progress Bar to the dataset downloading utility

* Updated progressbar to update by blcoks

* Added progressbar2 to the requirements

* fixed style issues

* Shifted from progressbar to tqdm
  • Loading branch information
maruthgoyal authored and soumith committed May 11, 2018
1 parent 73281b4 commit 47214f0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def find_version(*file_paths):
'pillow >= 4.1.1',
'six',
'torch',
'tqdm'
]

setup(
Expand Down
11 changes: 10 additions & 1 deletion torchvision/datasets/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
import os.path
import hashlib
import errno
from tqdm import tqdm


def gen_bar_updator(pbar):
def bar_update(count, block_size, total_size):
pbar.total = total_size / block_size
pbar.update(count)

return bar_update


def check_integrity(fpath, md5):
Expand Down Expand Up @@ -38,7 +47,7 @@ def download_url(url, root, filename, md5):
else:
try:
print('Downloading ' + url + ' to ' + fpath)
urllib.request.urlretrieve(url, fpath)
urllib.request.urlretrieve(url, fpath, reporthook=gen_bar_updator(tqdm()))
except:
if url[:5] == 'https':
url = url.replace('https:', 'http:')
Expand Down

0 comments on commit 47214f0

Please sign in to comment.