Download the data from source url, unless it's already here. Args: filename: string, name of the file in the directory. work_directory: string, path to working directory. source_url: url to download from if file doesn't exist. Returns: Path to resulting file
(filename, work_directory, source_url)
| 245 | |
| 246 | @deprecated(None, "Please write your own downloading logic.") |
| 247 | def _maybe_download(filename, work_directory, source_url): |
| 248 | """Download the data from source url, unless it's already here. |
| 249 | |
| 250 | Args: |
| 251 | filename: string, name of the file in the directory. |
| 252 | work_directory: string, path to working directory. |
| 253 | source_url: url to download from if file doesn't exist. |
| 254 | |
| 255 | Returns: |
| 256 | Path to resulting file. |
| 257 | """ |
| 258 | if not gfile.Exists(work_directory): |
| 259 | gfile.MakeDirs(work_directory) |
| 260 | filepath = os.path.join(work_directory, filename) |
| 261 | if not gfile.Exists(filepath): |
| 262 | urllib.request.urlretrieve(source_url, filepath) # noqa: S310 |
| 263 | with gfile.GFile(filepath) as f: |
| 264 | size = f.size() |
| 265 | print("Successfully downloaded", filename, size, "bytes.") |
| 266 | return filepath |
| 267 | |
| 268 | |
| 269 | @deprecated(None, "Please use alternatives such as: tensorflow_datasets.load('mnist')") |