ultralytics 8.0.69 HUB CI and ClearML fixes (#1888)

Co-authored-by: Victor Sonck <victor.sonck@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Glenn Jocher
2023-04-07 15:16:20 +02:00
committed by GitHub
parent d3f097314f
commit c2cd3fd20e
6 changed files with 67 additions and 88 deletions

View File

@ -2,7 +2,8 @@
import requests
from ultralytics.hub.utils import PREFIX, split_key
from ultralytics.hub.auth import Auth
from ultralytics.hub.utils import PREFIX
from ultralytics.yolo.utils import LOGGER, SETTINGS, USER_CONFIG_DIR, yaml_save
@ -17,7 +18,6 @@ def login(api_key=''):
from ultralytics import hub
hub.login('API_KEY')
"""
from ultralytics.hub.auth import Auth
Auth(api_key)
@ -42,20 +42,20 @@ def start(key=''):
key (str, optional): A string containing either the API key and model ID combination (apikey_modelid),
or the full model URL (https://hub.ultralytics.com/models/apikey_modelid).
"""
api_key, model_id = key.split('_')
LOGGER.warning(f"""
WARNING ⚠️ ultralytics.start() is deprecated in 8.0.60. Updated usage to train your Ultralytics HUB model is below:
WARNING ⚠️ ultralytics.start() is deprecated after 8.0.60. Updated usage to train Ultralytics HUB models is:
from ultralytics import YOLO
from ultralytics import YOLO, hub
model = YOLO('https://hub.ultralytics.com/models/{key}')
hub.login('{api_key}')
model = YOLO('https://hub.ultralytics.com/models/{model_id}')
model.train()""")
def reset_model(key=''):
def reset_model(model_id=''):
# Reset a trained model to an untrained state
api_key, model_id = split_key(key)
r = requests.post('https://api.ultralytics.com/model-reset', json={'apiKey': api_key, 'modelId': model_id})
r = requests.post('https://api.ultralytics.com/model-reset', json={'apiKey': Auth().api_key, 'modelId': model_id})
if r.status_code == 200:
LOGGER.info(f'{PREFIX}Model reset successfully')
return
@ -68,26 +68,24 @@ def export_fmts_hub():
return list(export_formats()['Argument'][1:]) + ['ultralytics_tflite', 'ultralytics_coreml']
def export_model(key='', format='torchscript'):
def export_model(model_id='', format='torchscript'):
# Export a model to all formats
assert format in export_fmts_hub(), f"Unsupported export format '{format}', valid formats are {export_fmts_hub()}"
api_key, model_id = split_key(key)
r = requests.post('https://api.ultralytics.com/export',
json={
'apiKey': api_key,
'apiKey': Auth().api_key,
'modelId': model_id,
'format': format})
assert r.status_code == 200, f'{PREFIX}{format} export failure {r.status_code} {r.reason}'
LOGGER.info(f'{PREFIX}{format} export started ✅')
def get_export(key='', format='torchscript'):
def get_export(model_id='', format='torchscript'):
# Get an exported model dictionary with download URL
assert format in export_fmts_hub, f"Unsupported export format '{format}', valid formats are {export_fmts_hub}"
api_key, model_id = split_key(key)
r = requests.post('https://api.ultralytics.com/get-export',
json={
'apiKey': api_key,
'apiKey': Auth().api_key,
'modelId': model_id,
'format': format})
assert r.status_code == 200, f'{PREFIX}{format} get_export failure {r.status_code} {r.reason}'

View File

@ -13,7 +13,7 @@ import requests
from tqdm import tqdm
from ultralytics.yolo.utils import (ENVIRONMENT, LOGGER, ONLINE, RANK, SETTINGS, TESTS_RUNNING, TQDM_BAR_FORMAT,
TryExcept, __version__, colorstr, emojis, get_git_origin_url, is_colab, is_git_dir,
TryExcept, __version__, colorstr, get_git_origin_url, is_colab, is_git_dir,
is_pip_package)
PREFIX = colorstr('Ultralytics HUB: ')
@ -80,29 +80,6 @@ def request_with_credentials(url: str) -> any:
return output.eval_js('_hub_tmp')
def split_key(key=''):
"""
Verify and split a 'api_key[sep]model_id' string, sep is one of '.' or '_'
Args:
key (str): The model key to split. If not provided, the user will be prompted to enter it.
Returns:
Tuple[str, str]: A tuple containing the API key and model ID.
"""
import getpass
error_string = emojis(f'{PREFIX}Invalid API key ⚠️\n') # error string
if not key:
key = getpass.getpass('Enter model key: ')
sep = '_' if '_' in key else None # separator
assert sep, error_string
api_key, model_id = key.split(sep)
assert len(api_key) and len(model_id), error_string
return api_key, model_id
def requests_with_progress(method, url, **kwargs):
"""
Make an HTTP request using the specified method and URL, with an optional progress bar.