glenn-jocher
commited on
Commit
•
b75c432
1
Parent(s):
051e9e8
GitHub API rate limit fallback (#1930)
Browse files- utils/google_utils.py +12 -8
utils/google_utils.py
CHANGED
@@ -16,28 +16,32 @@ def gsutil_getsize(url=''):
|
|
16 |
return eval(s.split(' ')[0]) if len(s) else 0 # bytes
|
17 |
|
18 |
|
19 |
-
def attempt_download(file):
|
20 |
# Attempt file download if does not exist
|
21 |
file = Path(str(file).strip().replace("'", '').lower())
|
22 |
|
23 |
if not file.exists():
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
27 |
|
|
|
28 |
if name in assets:
|
29 |
-
msg = f'{file} missing, try downloading from https://github.com/
|
30 |
redundant = False # second download option
|
31 |
try: # GitHub
|
32 |
-
|
33 |
-
url = f'https://github.com/ultralytics/yolov5/releases/download/{tag}/{name}'
|
34 |
print(f'Downloading {url} to {file}...')
|
35 |
torch.hub.download_url_to_file(url, file)
|
36 |
assert file.exists() and file.stat().st_size > 1E6 # check
|
37 |
except Exception as e: # GCP
|
38 |
print(f'Download error: {e}')
|
39 |
assert redundant, 'No secondary mirror'
|
40 |
-
url = f'https://storage.googleapis.com/
|
41 |
print(f'Downloading {url} to {file}...')
|
42 |
os.system(f'curl -L {url} -o {file}') # torch.hub.download_url_to_file(url, weights)
|
43 |
finally:
|
|
|
16 |
return eval(s.split(' ')[0]) if len(s) else 0 # bytes
|
17 |
|
18 |
|
19 |
+
def attempt_download(file, repo='ultralytics/yolov5'):
|
20 |
# Attempt file download if does not exist
|
21 |
file = Path(str(file).strip().replace("'", '').lower())
|
22 |
|
23 |
if not file.exists():
|
24 |
+
try:
|
25 |
+
response = requests.get(f'https://api.github.com/repos/{repo}/releases/latest').json() # github api
|
26 |
+
assets = [x['name'] for x in response['assets']] # release assets, i.e. ['yolov5s.pt', 'yolov5m.pt', ...]
|
27 |
+
tag = response['tag_name'] # i.e. 'v1.0'
|
28 |
+
except: # fallback plan
|
29 |
+
assets = ['yolov5.pt', 'yolov5.pt', 'yolov5l.pt', 'yolov5x.pt']
|
30 |
+
tag = subprocess.check_output('git tag', shell=True).decode('utf-8').split('\n')[-2]
|
31 |
|
32 |
+
name = file.name
|
33 |
if name in assets:
|
34 |
+
msg = f'{file} missing, try downloading from https://github.com/{repo}/releases/'
|
35 |
redundant = False # second download option
|
36 |
try: # GitHub
|
37 |
+
url = f'https://github.com/{repo}/releases/download/{tag}/{name}'
|
|
|
38 |
print(f'Downloading {url} to {file}...')
|
39 |
torch.hub.download_url_to_file(url, file)
|
40 |
assert file.exists() and file.stat().st_size > 1E6 # check
|
41 |
except Exception as e: # GCP
|
42 |
print(f'Download error: {e}')
|
43 |
assert redundant, 'No secondary mirror'
|
44 |
+
url = f'https://storage.googleapis.com/{repo}/ckpt/{name}'
|
45 |
print(f'Downloading {url} to {file}...')
|
46 |
os.system(f'curl -L {url} -o {file}') # torch.hub.download_url_to_file(url, weights)
|
47 |
finally:
|