Download and extract model tar file.
()
| 20 | |
| 21 | |
| 22 | def maybe_download_and_extract(): |
| 23 | """Download and extract model tar file.""" |
| 24 | dest_directory = FLAGS.model_dir |
| 25 | if not os.path.exists(dest_directory): |
| 26 | os.makedirs(dest_directory) |
| 27 | filename = DATA_URL.split('/')[-1] |
| 28 | filepath = os.path.join(dest_directory, filename) |
| 29 | print("ImageNet Inception DB filepath: %s" % filepath) |
| 30 | if not os.path.exists(filepath): |
| 31 | def _progress(count, block_size, total_size): |
| 32 | sys.stdout.write('\r>> Downloading %s %.1f%%' % ( |
| 33 | filename, |
| 34 | float(count * block_size) / float(total_size) * 100.0)) |
| 35 | sys.stdout.flush() |
| 36 | filepath, _ = urllib.request.urlretrieve(DATA_URL, filepath, _progress) |
| 37 | print() |
| 38 | statinfo = os.stat(filepath) |
| 39 | print('Succesfully downloaded', filename, statinfo.st_size, 'bytes.') |
| 40 | tarfile.open(filepath, 'r:gz').extractall(dest_directory) |
| 41 | |
| 42 | |
| 43 | def main(_): |