Skip to content

Commit

Permalink
Ability to dowlnoad older assets (#7767)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people committed May 11, 2022
1 parent d059d1d commit 4870064
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions utils/downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def safe_download(file, url, url2=None, min_bytes=1E0, error_msg=''):
LOGGER.info('')


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

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

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

0 comments on commit 4870064

Please sign in to comment.