16
16
FILES_TO_RUN = os .getenv ("FILES_TO_RUN" )
17
17
18
18
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
+
19
33
def download_url_to_file (url : str ,
20
34
dst : Optional [str ] = None ,
21
35
prefix : Optional [Path ] = None ,
@@ -46,7 +60,7 @@ def download_url_to_file(url: str,
46
60
if sha256 is not None and sha256 != digest :
47
61
Path (dst ).unlink ()
48
62
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 ) } " )
50
64
return Path (dst )
51
65
52
66
@@ -71,7 +85,7 @@ def download_nlp_data() -> None:
71
85
sha256 = "fb317e80248faeb62dc25ef3390ae24ca34b94e276bbc5141fd8862c2200bff5" ,
72
86
)
73
87
# 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 )
75
89
76
90
77
91
def download_dcgan_data () -> None :
@@ -80,7 +94,7 @@ def download_dcgan_data() -> None:
80
94
prefix = DATA_DIR ,
81
95
sha256 = "46fb89443c578308acf364d7d379fe1b9efb793042c0af734b6112e4fd3a8c74" ,
82
96
)
83
- unzip (z , BEGINNER_DATA_DIR )
97
+ unzip (z , BEGINNER_DATA_DIR / "celeba" )
84
98
85
99
86
100
def download_lenet_mnist () -> None :
@@ -99,8 +113,11 @@ def main() -> None:
99
113
INTERMEDIATE_DATA_DIR .mkdir (exist_ok = True )
100
114
PROTOTYPE_DATA_DIR .mkdir (exist_ok = True )
101
115
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 ()
104
121
if FILES_TO_RUN is None or "dcgan_faces_tutorial" in FILES_TO_RUN :
105
122
download_dcgan_data ()
106
123
if FILES_TO_RUN is None or "fgsm_tutorial" in FILES_TO_RUN :
0 commit comments