Load file form http url, will download models if necessary. Ref:https://github.com/1adrianb/face-alignment/blob/master/face_alignment/utils.py Args: url (str): URL to be downloaded. model_dir (str): The path to save the downloaded model. Should be a full path. If None, use
(url, model_dir=None, progress=True, file_name=None)
| 79 | |
| 80 | # https://github.com/XPixelGroup/BasicSR/blob/master/basicsr/utils/download_util.py/ |
| 81 | def load_file_from_url(url, model_dir=None, progress=True, file_name=None): |
| 82 | """Load file form http url, will download models if necessary. |
| 83 | |
| 84 | Ref:https://github.com/1adrianb/face-alignment/blob/master/face_alignment/utils.py |
| 85 | |
| 86 | Args: |
| 87 | url (str): URL to be downloaded. |
| 88 | model_dir (str): The path to save the downloaded model. Should be a full path. If None, use pytorch hub_dir. |
| 89 | Default: None. |
| 90 | progress (bool): Whether to show the download progress. Default: True. |
| 91 | file_name (str): The downloaded file name. If None, use the file name in the url. Default: None. |
| 92 | |
| 93 | Returns: |
| 94 | str: The path to the downloaded file. |
| 95 | """ |
| 96 | if model_dir is None: # use the pytorch hub_dir |
| 97 | hub_dir = get_dir() |
| 98 | model_dir = os.path.join(hub_dir, "checkpoints") |
| 99 | |
| 100 | os.makedirs(model_dir, exist_ok=True) |
| 101 | |
| 102 | parts = urlparse(url) |
| 103 | filename = os.path.basename(parts.path) |
| 104 | if file_name is not None: |
| 105 | filename = file_name |
| 106 | cached_file = os.path.abspath(os.path.join(model_dir, filename)) |
| 107 | if not os.path.exists(cached_file): |
| 108 | print(f'Downloading: "{url}" to {cached_file}\n') |
| 109 | download_url_to_file(url, cached_file, hash_prefix=None, progress=progress) |
| 110 | return cached_file |
| 111 | |
| 112 | |
| 113 | def load_model_from_url(url: str) -> Dict[str, torch.Tensor]: |
no outgoing calls
no test coverage detected