Skip to content

Commit 4870064

Browse files
CristiFatipre-commit-ci[bot]glenn-jocher
authored
Ability to dowlnoad older assets (#7767)
* Ability to dowlnoad older assets * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Cleanup * Cleanup2 Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
1 parent d059d1d commit 4870064

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

utils/downloads.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ def safe_download(file, url, url2=None, min_bytes=1E0, error_msg=''):
4343
LOGGER.info('')
4444

4545

46-
def attempt_download(file, repo='ultralytics/yolov5'): # from utils.downloads import *; attempt_download()
47-
# Attempt file download if does not exist
46+
def attempt_download(file, repo='ultralytics/yolov5', release='latest'):
47+
# Attempt file download from GitHub release assets if not found locally
4848
from utils.general import LOGGER
4949

5050
file = Path(str(file).strip().replace("'", ''))
@@ -62,8 +62,10 @@ def attempt_download(file, repo='ultralytics/yolov5'): # from utils.downloads i
6262

6363
# GitHub assets
6464
file.parent.mkdir(parents=True, exist_ok=True) # make parent dir (if required)
65+
if release != 'latest' and not release.startswith('tags/'):
66+
release = f'tags/{release}' # prepend i.e. tags/v6.1
6567
try:
66-
response = requests.get(f'https://api.github.com/repos/{repo}/releases/latest').json() # github api
68+
response = requests.get(f'https://api.github.com/repos/{repo}/releases/{release}').json() # github api
6769
assets = [x['name'] for x in response['assets']] # release assets, i.e. ['yolov5s.pt', 'yolov5m.pt', ...]
6870
tag = response['tag_name'] # i.e. 'v1.0'
6971
except Exception: # fallback plan

0 commit comments

Comments
 (0)