MCPcopy Create free account
hub / github.com/csxmli2016/MARCONetPlusPlus / download_file_from_github

Function download_file_from_github

utils/download_github.py:6–35  ·  view source on GitHub ↗

Load file form http url, will download models if necessary. Reference: 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 Non

(url, model_dir=None, progress=True, file_name=None)

Source from the content-addressed store, hash-verified

4from urllib.parse import urlparse
5
6def download_file_from_github(url, model_dir=None, progress=True, file_name=None):
7 """Load file form http url, will download models if necessary.
8
9 Reference: https://github.com/1adrianb/face-alignment/blob/master/face_alignment/utils.py
10
11 Args:
12 url (str): URL to be downloaded.
13 model_dir (str): The path to save the downloaded model. Should be a full path. If None, use pytorch hub_dir.
14 Default: None.
15 progress (bool): Whether to show the download progress. Default: True.
16 file_name (str): The downloaded file name. If None, use the file name in the url. Default: None.
17
18 Returns:
19 str: The path to the downloaded file.
20 """
21 if model_dir is None: # use the pytorch hub_dir
22 hub_dir = get_dir()
23 model_dir = os.path.join(hub_dir, 'checkpoints')
24
25 os.makedirs(model_dir, exist_ok=True)
26
27 parts = urlparse(url)
28 filename = os.path.basename(parts.path)
29 if file_name is not None:
30 filename = file_name
31 cached_file = os.path.abspath(os.path.join(model_dir, filename))
32 if not os.path.exists(cached_file):
33 print(f'Downloading: "{url}" to {cached_file}\n')
34 download_url_to_file(url, cached_file, hash_prefix=None, progress=progress)
35 return cached_file
36
37
38os.makedirs('./checkpoints', exist_ok=True)

Callers 1

download_github.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected