Skip to content

Commit 8ded440

Browse files
DEKHTIARJonathanzsdonghao
authored andcommitted
ProgressBar added for dataset download. Now stops bombarding the console. (#502)
1 parent 4a188e7 commit 8ded440

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
numpy
2+
progressbar2==3.37.0
23
scipy
34
scikit-image
45
matplotlib

tensorlayer/files.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import tarfile
1010
import time
1111
import zipfile
12+
import progressbar
1213

1314
import numpy as np
1415
import tensorflow as tf
@@ -2030,14 +2031,17 @@ def maybe_download_and_extract(filename, working_directory, url_source, extract=
20302031

20312032
# We first define a download function, supporting both Python 2 and 3.
20322033
def _download(filename, working_directory, url_source):
2033-
def _dlProgress(count, blockSize, totalSize):
2034+
2035+
progress_bar = progressbar.ProgressBar()
2036+
2037+
def _dlProgress(count, blockSize, totalSize, pbar=progress_bar):
20342038
if (totalSize != 0):
2035-
totalBlocks = math.ceil(float(totalSize) / float(blockSize))
2036-
percent = float(count) / float(totalBlocks) * 100.0
2037-
# https://www.quora.com/How-can-I-delete-the-last-printed-line-in-Python-language
2038-
sys.stdout.write('\033[F') # back to previous line
2039-
sys.stdout.write('\033[K') # clear line
2040-
sys.stdout.write('Downloading %s...%g%%\n' % (filename, percent))
2039+
2040+
if not pbar.max_value:
2041+
totalBlocks = math.ceil(float(totalSize) / float(blockSize))
2042+
pbar.max_value = int(totalBlocks)
2043+
2044+
pbar.update(count, force=True)
20412045

20422046
if sys.version_info[0] == 2:
20432047
from urllib import urlretrieve

0 commit comments

Comments
 (0)