add yolo v10 and modify pipeline
This commit is contained in:
@ -10,14 +10,29 @@ from pathlib import Path
|
||||
|
||||
import requests
|
||||
|
||||
from ultralytics.utils import (ENVIRONMENT, LOGGER, ONLINE, RANK, SETTINGS, TESTS_RUNNING, TQDM, TryExcept, __version__,
|
||||
colorstr, get_git_origin_url, is_colab, is_git_dir, is_pip_package)
|
||||
from ultralytics.utils import (
|
||||
ENVIRONMENT,
|
||||
LOGGER,
|
||||
ONLINE,
|
||||
RANK,
|
||||
SETTINGS,
|
||||
TESTS_RUNNING,
|
||||
TQDM,
|
||||
TryExcept,
|
||||
__version__,
|
||||
colorstr,
|
||||
get_git_origin_url,
|
||||
is_colab,
|
||||
is_git_dir,
|
||||
is_pip_package,
|
||||
)
|
||||
from ultralytics.utils.downloads import GITHUB_ASSETS_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')
|
||||
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")
|
||||
|
||||
PREFIX = colorstr("Ultralytics HUB: ")
|
||||
HELP_MSG = "If this issue persists please visit https://github.com/ultralytics/hub/issues for assistance."
|
||||
|
||||
|
||||
def request_with_credentials(url: str) -> any:
|
||||
@ -34,11 +49,13 @@ def request_with_credentials(url: str) -> any:
|
||||
OSError: If the function is not run in a Google Colab environment.
|
||||
"""
|
||||
if not is_colab():
|
||||
raise OSError('request_with_credentials() must run in a Colab environment')
|
||||
raise OSError("request_with_credentials() must run in a Colab environment")
|
||||
from google.colab import output # noqa
|
||||
from IPython import display # noqa
|
||||
|
||||
display.display(
|
||||
display.Javascript("""
|
||||
display.Javascript(
|
||||
"""
|
||||
window._hub_tmp = new Promise((resolve, reject) => {
|
||||
const timeout = setTimeout(() => reject("Failed authenticating existing browser session"), 5000)
|
||||
fetch("%s", {
|
||||
@ -53,8 +70,11 @@ def request_with_credentials(url: str) -> any:
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
""" % url))
|
||||
return output.eval_js('_hub_tmp')
|
||||
"""
|
||||
% url
|
||||
)
|
||||
)
|
||||
return output.eval_js("_hub_tmp")
|
||||
|
||||
|
||||
def requests_with_progress(method, url, **kwargs):
|
||||
@ -64,22 +84,23 @@ def requests_with_progress(method, url, **kwargs):
|
||||
Args:
|
||||
method (str): The HTTP method to use (e.g. 'GET', 'POST').
|
||||
url (str): The URL to send the request to.
|
||||
**kwargs (dict): Additional keyword arguments to pass to the underlying `requests.request` function.
|
||||
**kwargs (any): Additional keyword arguments to pass to the underlying `requests.request` function.
|
||||
|
||||
Returns:
|
||||
(requests.Response): The response object from the HTTP request.
|
||||
|
||||
Note:
|
||||
If 'progress' is set to True, the progress bar will display the download progress
|
||||
for responses with a known content length.
|
||||
- If 'progress' is set to True, the progress bar will display the download progress for responses with a known
|
||||
content length.
|
||||
- If 'progress' is a number then progress bar will display assuming content length = progress.
|
||||
"""
|
||||
progress = kwargs.pop('progress', False)
|
||||
progress = kwargs.pop("progress", False)
|
||||
if not progress:
|
||||
return requests.request(method, url, **kwargs)
|
||||
response = requests.request(method, url, stream=True, **kwargs)
|
||||
total = int(response.headers.get('content-length', 0)) # total size
|
||||
total = int(response.headers.get("content-length", 0) if isinstance(progress, bool) else progress) # total size
|
||||
try:
|
||||
pbar = TQDM(total=total, unit='B', unit_scale=True, unit_divisor=1024)
|
||||
pbar = TQDM(total=total, unit="B", unit_scale=True, unit_divisor=1024)
|
||||
for data in response.iter_content(chunk_size=1024):
|
||||
pbar.update(len(data))
|
||||
pbar.close()
|
||||
@ -101,7 +122,7 @@ def smart_request(method, url, retry=3, timeout=30, thread=True, code=-1, verbos
|
||||
code (int, optional): An identifier for the request, used for logging purposes. Default is -1.
|
||||
verbose (bool, optional): A flag to determine whether to print out to console or not. Default is True.
|
||||
progress (bool, optional): Whether to show a progress bar during the request. Default is False.
|
||||
**kwargs (dict): Keyword arguments to be passed to the requests function specified in method.
|
||||
**kwargs (any): Keyword arguments to be passed to the requests function specified in method.
|
||||
|
||||
Returns:
|
||||
(requests.Response): The HTTP response object. If the request is executed in a separate thread, returns None.
|
||||
@ -120,25 +141,27 @@ def smart_request(method, url, retry=3, timeout=30, thread=True, code=-1, verbos
|
||||
if r.status_code < 300: # return codes in the 2xx range are generally considered "good" or "successful"
|
||||
break
|
||||
try:
|
||||
m = r.json().get('message', 'No JSON message.')
|
||||
m = r.json().get("message", "No JSON message.")
|
||||
except AttributeError:
|
||||
m = 'Unable to read JSON.'
|
||||
m = "Unable to read JSON."
|
||||
if i == 0:
|
||||
if r.status_code in retry_codes:
|
||||
m += f' Retrying {retry}x for {timeout}s.' if retry else ''
|
||||
m += f" Retrying {retry}x for {timeout}s." if retry else ""
|
||||
elif r.status_code == 429: # rate limit
|
||||
h = r.headers # response headers
|
||||
m = f"Rate limit reached ({h['X-RateLimit-Remaining']}/{h['X-RateLimit-Limit']}). " \
|
||||
m = (
|
||||
f"Rate limit reached ({h['X-RateLimit-Remaining']}/{h['X-RateLimit-Limit']}). "
|
||||
f"Please retry after {h['Retry-After']}s."
|
||||
)
|
||||
if verbose:
|
||||
LOGGER.warning(f'{PREFIX}{m} {HELP_MSG} ({r.status_code} #{code})')
|
||||
LOGGER.warning(f"{PREFIX}{m} {HELP_MSG} ({r.status_code} #{code})")
|
||||
if r.status_code not in retry_codes:
|
||||
return r
|
||||
time.sleep(2 ** i) # exponential standoff
|
||||
time.sleep(2**i) # exponential standoff
|
||||
return r
|
||||
|
||||
args = method, url
|
||||
kwargs['progress'] = progress
|
||||
kwargs["progress"] = progress
|
||||
if thread:
|
||||
threading.Thread(target=func, args=args, kwargs=kwargs, daemon=True).start()
|
||||
else:
|
||||
@ -157,29 +180,29 @@ class Events:
|
||||
enabled (bool): A flag to enable or disable Events based on certain conditions.
|
||||
"""
|
||||
|
||||
url = 'https://www.google-analytics.com/mp/collect?measurement_id=G-X8NCJYTQXM&api_secret=QLQrATrNSwGRFRLE-cbHJw'
|
||||
url = "https://www.google-analytics.com/mp/collect?measurement_id=G-X8NCJYTQXM&api_secret=QLQrATrNSwGRFRLE-cbHJw"
|
||||
|
||||
def __init__(self):
|
||||
"""
|
||||
Initializes the Events object with default values for events, rate_limit, and metadata.
|
||||
"""
|
||||
"""Initializes the Events object with default values for events, rate_limit, and metadata."""
|
||||
self.events = [] # events list
|
||||
self.rate_limit = 60.0 # rate limit (seconds)
|
||||
self.t = 0.0 # rate limit timer (seconds)
|
||||
self.metadata = {
|
||||
'cli': Path(sys.argv[0]).name == 'yolo',
|
||||
'install': 'git' if is_git_dir() else 'pip' if is_pip_package() else 'other',
|
||||
'python': '.'.join(platform.python_version_tuple()[:2]), # i.e. 3.10
|
||||
'version': __version__,
|
||||
'env': ENVIRONMENT,
|
||||
'session_id': round(random.random() * 1E15),
|
||||
'engagement_time_msec': 1000}
|
||||
self.enabled = \
|
||||
SETTINGS['sync'] and \
|
||||
RANK in (-1, 0) and \
|
||||
not TESTS_RUNNING and \
|
||||
ONLINE and \
|
||||
(is_pip_package() or get_git_origin_url() == 'https://github.com/ultralytics/ultralytics.git')
|
||||
"cli": Path(sys.argv[0]).name == "yolo",
|
||||
"install": "git" if is_git_dir() else "pip" if is_pip_package() else "other",
|
||||
"python": ".".join(platform.python_version_tuple()[:2]), # i.e. 3.10
|
||||
"version": __version__,
|
||||
"env": ENVIRONMENT,
|
||||
"session_id": round(random.random() * 1e15),
|
||||
"engagement_time_msec": 1000,
|
||||
}
|
||||
self.enabled = (
|
||||
SETTINGS["sync"]
|
||||
and RANK in (-1, 0)
|
||||
and not TESTS_RUNNING
|
||||
and ONLINE
|
||||
and (is_pip_package() or get_git_origin_url() == "https://github.com/ultralytics/ultralytics.git")
|
||||
)
|
||||
|
||||
def __call__(self, cfg):
|
||||
"""
|
||||
@ -195,11 +218,13 @@ class Events:
|
||||
# Attempt to add to events
|
||||
if len(self.events) < 25: # Events list limited to 25 events (drop any events past this)
|
||||
params = {
|
||||
**self.metadata, 'task': cfg.task,
|
||||
'model': cfg.model if cfg.model in GITHUB_ASSETS_NAMES else 'custom'}
|
||||
if cfg.mode == 'export':
|
||||
params['format'] = cfg.format
|
||||
self.events.append({'name': cfg.mode, 'params': params})
|
||||
**self.metadata,
|
||||
"task": cfg.task,
|
||||
"model": cfg.model if cfg.model in GITHUB_ASSETS_NAMES else "custom",
|
||||
}
|
||||
if cfg.mode == "export":
|
||||
params["format"] = cfg.format
|
||||
self.events.append({"name": cfg.mode, "params": params})
|
||||
|
||||
# Check rate limit
|
||||
t = time.time()
|
||||
@ -208,10 +233,10 @@ class Events:
|
||||
return
|
||||
|
||||
# Time is over rate limiter, send now
|
||||
data = {'client_id': SETTINGS['uuid'], 'events': self.events} # SHA-256 anonymized UUID hash and events list
|
||||
data = {"client_id": SETTINGS["uuid"], "events": self.events} # SHA-256 anonymized UUID hash and events list
|
||||
|
||||
# POST equivalent to requests.post(self.url, json=data)
|
||||
smart_request('post', self.url, json=data, retry=0, verbose=False)
|
||||
smart_request("post", self.url, json=data, retry=0, verbose=False)
|
||||
|
||||
# Reset events and rate limit timer
|
||||
self.events = []
|
||||
|
Reference in New Issue
Block a user