Unverified Commit 6cc4970b authored by Francisco Massa's avatar Francisco Massa Committed by GitHub
Browse files

Fix for no tqdm (#770)

* Fixes for PyTorch version of tqdm

* Flake

* Flake fix
parent 8eb6f887
......@@ -46,8 +46,10 @@ if __name__ == "__main__":
start_time = timer()
batch_count = 20 * args.nThreads
for _ in tqdm(range(batch_count)):
batch = next(train_iter)
with tqdm(total=batch_count) as pbar:
for _ in tqdm(range(batch_count)):
pbar.update(1)
batch = next(train_iter)
end_time = timer()
print("Performance: {dataset:.0f} minutes/dataset, {batch:.1f} ms/batch,"
" {image:.2f} ms/image {rate:.0f} images/sec"
......
import shutil
import tempfile
import torch
import torchvision.datasets.utils as utils
import unittest
class Tester(unittest.TestCase):
def test_download_url(self):
temp_dir = tempfile.mkdtemp()
url = "http://github.com/pytorch/vision/archive/master.zip"
utils.download_url(url, temp_dir)
shutil.rmtree(temp_dir)
def test_download_url_retry_http(self):
temp_dir = tempfile.mkdtemp()
url = "https://github.com/pytorch/vision/archive/master.zip"
utils.download_url(url, temp_dir)
shutil.rmtree(temp_dir)
if __name__ == '__main__':
unittest.main()
......@@ -5,7 +5,9 @@ import errno
from torch.utils.model_zoo import tqdm
def gen_bar_updater(pbar):
def gen_bar_updater():
pbar = tqdm(total=None)
def bar_update(count, block_size, total_size):
if pbar.total is None and total_size:
pbar.total = total_size
......@@ -70,7 +72,7 @@ def download_url(url, root, filename=None, md5=None):
print('Downloading ' + url + ' to ' + fpath)
urllib.request.urlretrieve(
url, fpath,
reporthook=gen_bar_updater(tqdm())
reporthook=gen_bar_updater()
)
except OSError:
if url[:5] == 'https':
......@@ -79,7 +81,7 @@ def download_url(url, root, filename=None, md5=None):
' Downloading ' + url + ' to ' + fpath)
urllib.request.urlretrieve(
url, fpath,
reporthook=gen_bar_updater(tqdm())
reporthook=gen_bar_updater()
)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment