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