8.0.60 new HUB training syntax (#1753)

Co-authored-by: Rafael Pierre <97888102+rafaelvp-db@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ayush Chaurasia <ayush.chaurarsia@gmail.com>
Co-authored-by: Semih Demirel <85176438+semihhdemirel@users.noreply.github.com>
This commit is contained in:
Glenn Jocher 2023-04-03 02:36:58 +02:00 committed by GitHub
parent e7876e1ba9
commit 84948651cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 405 additions and 122 deletions

View file

@ -2,47 +2,51 @@
import requests
from ultralytics.hub.auth import Auth
from ultralytics.hub.session import HUBTrainingSession
from ultralytics.hub.utils import PREFIX, split_key
from ultralytics.yolo.engine.model import YOLO
from ultralytics.yolo.utils import LOGGER, emojis
from ultralytics.yolo.utils import LOGGER
def login(api_key=''):
"""
Log in to the Ultralytics HUB API using the provided API key.
Args:
api_key (str, optional): May be an API key or a combination API key and model ID, i.e. key_id
Example:
from ultralytics import hub
hub.login('your_api_key')
"""
from ultralytics.hub.auth import Auth
Auth(api_key)
def logout():
"""
Logout Ultralytics HUB
Example:
from ultralytics import hub
hub.logout()
"""
LOGGER.warning('WARNING ⚠️ This method is not yet implemented.')
def start(key=''):
"""
Start training models with Ultralytics HUB. Usage: from ultralytics.hub import start; start('API_KEY')
Start training models with Ultralytics HUB (DEPRECATED).
Args:
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).
"""
auth = Auth(key)
model_id = split_key(key)[1] if auth.get_state() else request_api_key(auth)
if not model_id:
raise ConnectionError(emojis('Connecting with global API key is not currently supported. ❌'))
LOGGER.warning(f"""
WARNING ultralytics.start() is deprecated in 8.0.60. Updated usage to train your Ultralytics HUB model is below:
session = HUBTrainingSession(model_id=model_id, auth=auth)
session.check_disk_space()
from ultralytics import YOLO
model = YOLO(model=session.model_file, session=session)
model.train(**session.train_args)
def request_api_key(auth, max_attempts=3):
"""
Prompt the user to input their API key. Returns the model ID.
"""
import getpass
for attempts in range(max_attempts):
LOGGER.info(f'{PREFIX}Login. Attempt {attempts + 1} of {max_attempts}')
input_key = getpass.getpass(
'Enter your Ultralytics API Key from https://hub.ultralytics.com/settings?tab=api+keys:\n')
auth.api_key, model_id = split_key(input_key)
if auth.authenticate():
LOGGER.info(f'{PREFIX}Authenticated ✅')
return model_id
LOGGER.warning(f'{PREFIX}Invalid API key ⚠️\n')
raise ConnectionError(emojis(f'{PREFIX}Failed to authenticate ❌'))
model = YOLO('https://hub.ultralytics.com/models/{key}')
model.train()""")
def reset_model(key=''):