Add HUB URL environment variables (#3988)
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>
This commit is contained in:
@ -4,7 +4,7 @@ import requests
|
||||
|
||||
from ultralytics.data.utils import HUBDatasetStats
|
||||
from ultralytics.hub.auth import Auth
|
||||
from ultralytics.hub.utils import PREFIX
|
||||
from ultralytics.hub.utils import HUB_API_ROOT, HUB_WEB_ROOT, PREFIX
|
||||
from ultralytics.utils import LOGGER, SETTINGS, USER_CONFIG_DIR, yaml_save
|
||||
|
||||
|
||||
@ -50,13 +50,13 @@ WARNING ⚠️ ultralytics.start() is deprecated after 8.0.60. Updated usage to
|
||||
from ultralytics import YOLO, hub
|
||||
|
||||
hub.login('{api_key}')
|
||||
model = YOLO('https://hub.ultralytics.com/models/{model_id}')
|
||||
model = YOLO('{HUB_WEB_ROOT}/models/{model_id}')
|
||||
model.train()""")
|
||||
|
||||
|
||||
def reset_model(model_id=''):
|
||||
"""Reset a trained model to an untrained state."""
|
||||
r = requests.post('https://api.ultralytics.com/model-reset', json={'apiKey': Auth().api_key, 'modelId': model_id})
|
||||
r = requests.post(f'{HUB_API_ROOT}/model-reset', json={'apiKey': Auth().api_key, 'modelId': model_id})
|
||||
if r.status_code == 200:
|
||||
LOGGER.info(f'{PREFIX}Model reset successfully')
|
||||
return
|
||||
@ -72,7 +72,7 @@ def export_fmts_hub():
|
||||
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()}"
|
||||
r = requests.post(f'https://api.ultralytics.com/v1/models/{model_id}/export',
|
||||
r = requests.post(f'{HUB_API_ROOT}/v1/models/{model_id}/export',
|
||||
json={'format': format},
|
||||
headers={'x-api-key': Auth().api_key})
|
||||
assert r.status_code == 200, f'{PREFIX}{format} export failure {r.status_code} {r.reason}'
|
||||
@ -82,7 +82,7 @@ def export_model(model_id='', 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()}"
|
||||
r = requests.post('https://api.ultralytics.com/get-export',
|
||||
r = requests.post(f'{HUB_API_ROOT}/get-export',
|
||||
json={
|
||||
'apiKey': Auth().api_key,
|
||||
'modelId': model_id,
|
||||
@ -110,7 +110,7 @@ def check_dataset(path='', task='detect'):
|
||||
```
|
||||
"""
|
||||
HUBDatasetStats(path=path, task=task).get_json()
|
||||
LOGGER.info('Checks completed correctly ✅. Upload this dataset to https://hub.ultralytics.com/datasets/.')
|
||||
LOGGER.info(f'Checks completed correctly ✅. Upload this dataset to {HUB_WEB_ROOT}/datasets/.')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -2,10 +2,10 @@
|
||||
|
||||
import requests
|
||||
|
||||
from ultralytics.hub.utils import HUB_API_ROOT, PREFIX, request_with_credentials
|
||||
from ultralytics.hub.utils import HUB_API_ROOT, HUB_WEB_ROOT, PREFIX, request_with_credentials
|
||||
from ultralytics.utils import LOGGER, SETTINGS, emojis, is_colab
|
||||
|
||||
API_KEY_URL = 'https://hub.ultralytics.com/settings?tab=api+keys'
|
||||
API_KEY_URL = f'{HUB_WEB_ROOT}/settings?tab=api+keys'
|
||||
|
||||
|
||||
class Auth:
|
||||
|
@ -6,7 +6,7 @@ from time import sleep
|
||||
|
||||
import requests
|
||||
|
||||
from ultralytics.hub.utils import HUB_API_ROOT, PREFIX, smart_request
|
||||
from ultralytics.hub.utils import HUB_API_ROOT, HUB_WEB_ROOT, PREFIX, smart_request
|
||||
from ultralytics.utils import LOGGER, __version__, checks, emojis, is_colab, threaded
|
||||
from ultralytics.utils.errors import HUBModelError
|
||||
|
||||
@ -49,21 +49,21 @@ class HUBTrainingSession:
|
||||
from ultralytics.hub.auth import Auth
|
||||
|
||||
# Parse input
|
||||
if url.startswith('https://hub.ultralytics.com/models/'):
|
||||
url = url.split('https://hub.ultralytics.com/models/')[-1]
|
||||
if url.startswith(f'{HUB_WEB_ROOT}/models/'):
|
||||
url = url.split(f'{HUB_WEB_ROOT}/models/')[-1]
|
||||
if [len(x) for x in url.split('_')] == [42, 20]:
|
||||
key, model_id = url.split('_')
|
||||
elif len(url) == 20:
|
||||
key, model_id = '', url
|
||||
else:
|
||||
raise HUBModelError(f"model='{url}' not found. Check format is correct, i.e. "
|
||||
f"model='https://hub.ultralytics.com/models/MODEL_ID' and try again.")
|
||||
f"model='{HUB_WEB_ROOT}/models/MODEL_ID' and try again.")
|
||||
|
||||
# Authorize
|
||||
auth = Auth(key)
|
||||
self.agent_id = None # identifies which instance is communicating with server
|
||||
self.model_id = model_id
|
||||
self.model_url = f'https://hub.ultralytics.com/models/{model_id}'
|
||||
self.model_url = f'{HUB_WEB_ROOT}/models/{model_id}'
|
||||
self.api_url = f'{HUB_API_ROOT}/v1/models/{model_id}'
|
||||
self.auth_header = auth.get_auth_header()
|
||||
self.rate_limits = {'metrics': 3.0, 'ckpt': 900.0, 'heartbeat': 300.0} # rate limits (seconds)
|
||||
|
@ -18,6 +18,7 @@ from ultralytics.utils.downloads import GITHUB_ASSET_NAMES
|
||||
PREFIX = colorstr('Ultralytics HUB: ')
|
||||
HELP_MSG = 'If this issue persists please visit https://github.com/ultralytics/hub/issues for assistance.'
|
||||
HUB_API_ROOT = os.environ.get('ULTRALYTICS_HUB_API', 'https://api.ultralytics.com')
|
||||
HUB_WEB_ROOT = os.environ.get('ULTRALYTICS_HUB_WEB', 'https://hub.ultralytics.com')
|
||||
|
||||
|
||||
def request_with_credentials(url: str) -> any:
|
||||
|
Reference in New Issue
Block a user