(filename, url, sha256_hash_prefix=None)
| 25 | # with open(filename, 'rb', buffering=0) as f: |
| 26 | # return hashlib.file_digest(f, 'sha256').hexdigest() |
| 27 | def ensure_file_downloaded(filename, url, sha256_hash_prefix=None): |
| 28 | import torch |
| 29 | # Do not check the hash every time - it is somewhat time-consumin |
| 30 | if os.path.exists(filename): |
| 31 | return |
| 32 | |
| 33 | if type(url) is not list: |
| 34 | url = [url] |
| 35 | for cur_url in url: |
| 36 | try: |
| 37 | print("Downloading", cur_url, "to", filename) |
| 38 | torch.hub.download_url_to_file(cur_url, filename, sha256_hash_prefix) |
| 39 | if os.path.exists(filename): |
| 40 | return # The correct model was downloaded, no need to try more |
| 41 | except: |
| 42 | pass |
| 43 | raise RuntimeError(f'Download failed. ' |
| 44 | f'Try again later or manually download the file {filename} to location {url}.') |
no outgoing calls
no test coverage detected