Skip to content

Commit

Permalink
Progress Bar for download_url (pytorch#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 varunagrawal committed Jul 23, 2018
1 parent 0146b40 commit 7715bab
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 @@ -37,6 +37,7 @@ def find_version(*file_paths):
'pillow >= 4.1.1',
'six',
'torch',
'tqdm'
]


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 7715bab

Please sign in to comment.