Skip to content

Commit 314b1d7

Browse files
committed
More improvements/fixes
1 parent 882ec11 commit 314b1d7

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

.jenkins/download_data.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@
1616
FILES_TO_RUN = os.getenv("FILES_TO_RUN")
1717

1818

19+
def size_fmt(nbytes: int) -> str:
20+
"""Returns a formatted file size string"""
21+
KB = 1024
22+
MB = 1024 * KB
23+
GB = 1024 * MB
24+
if abs(nbytes) >= GB:
25+
return f"{nbytes * 1.0 / GB:.2f} Gb"
26+
elif abs(nbytes) >= MB:
27+
return f"{nbytes * 1.0 / MB:.2f} Mb"
28+
elif abs(nbytes) >= KB:
29+
return f"{nbytes * 1.0 / KB:.2f} Kb"
30+
return str(nbytes) + " bytes"
31+
32+
1933
def download_url_to_file(url: str,
2034
dst: Optional[str] = None,
2135
prefix: Optional[Path] = None,
@@ -46,7 +60,7 @@ def download_url_to_file(url: str,
4660
if sha256 is not None and sha256 != digest:
4761
Path(dst).unlink()
4862
raise RuntimeError(f"Downloaded {url} has unexpected sha256sum {digest} should be {sha256}")
49-
print(f"Downloaded {url} sha256sum={digest} size={file_size}")
63+
print(f"Downloaded {url} sha256sum={digest} size={size_fmt(file_size)}")
5064
return Path(dst)
5165

5266

@@ -71,7 +85,7 @@ def download_nlp_data() -> None:
7185
sha256="fb317e80248faeb62dc25ef3390ae24ca34b94e276bbc5141fd8862c2200bff5",
7286
)
7387
# This will unzip all files in data.zip to intermediate_source/data/ folder
74-
unzip(z, INTERMEDIATE_DATA_DIR)
88+
unzip(z, INTERMEDIATE_DATA_DIR.parent)
7589

7690

7791
def download_dcgan_data() -> None:
@@ -80,7 +94,7 @@ def download_dcgan_data() -> None:
8094
prefix=DATA_DIR,
8195
sha256="46fb89443c578308acf364d7d379fe1b9efb793042c0af734b6112e4fd3a8c74",
8296
)
83-
unzip(z, BEGINNER_DATA_DIR)
97+
unzip(z, BEGINNER_DATA_DIR / "celeba")
8498

8599

86100
def download_lenet_mnist() -> None:
@@ -99,8 +113,11 @@ def main() -> None:
99113
INTERMEDIATE_DATA_DIR.mkdir(exist_ok=True)
100114
PROTOTYPE_DATA_DIR.mkdir(exist_ok=True)
101115

102-
download_hymenoptera_data()
103-
download_nlp_data()
116+
if FILES_TO_RUN is None or "transfer_learning_tutoria" in FILES_TO_RUN:
117+
download_hymenoptera_data()
118+
nlp_tutorials = ["seq2seq_translation_tutorial", "char_rnn_classification_tutorial", "char_rnn_generation_tutorial"]
119+
if FILES_TO_RUN is None or any(x in FILES_TO_RUN for x in nlp_tutorials):
120+
download_nlp_data()
104121
if FILES_TO_RUN is None or "dcgan_faces_tutorial" in FILES_TO_RUN:
105122
download_dcgan_data()
106123
if FILES_TO_RUN is None or "fgsm_tutorial" in FILES_TO_RUN:

0 commit comments

Comments
 (0)