Reference for ultralytics/hub/utils.py
Note
This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/hub/utils.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
ultralytics.hub.utils.Events
A class for collecting anonymous event analytics. Event analytics are enabled when sync=True in settings and disabled when sync=False. Run 'yolo settings' to see and update settings.
Attributes:
Name | Type | Description |
---|---|---|
url |
str
|
The URL to send anonymous events. |
rate_limit |
float
|
The rate limit in seconds for sending events. |
metadata |
dict
|
A dictionary containing metadata about the environment. |
enabled |
bool
|
A flag to enable or disable Events based on certain conditions. |
Source code in ultralytics/hub/utils.py
__call__
Attempts to add a new event to the events list and send events if the rate limit is reached.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cfg
|
IterableSimpleNamespace
|
The configuration object containing mode and task information. |
required |
Source code in ultralytics/hub/utils.py
ultralytics.hub.utils.request_with_credentials
Make an AJAX request with cookies attached in a Google Colab environment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str
|
The URL to make the request to. |
required |
Returns:
Type | Description |
---|---|
any
|
The response data from the AJAX request. |
Raises:
Type | Description |
---|---|
OSError
|
If the function is not run in a Google Colab environment. |
Source code in ultralytics/hub/utils.py
ultralytics.hub.utils.requests_with_progress
Make an HTTP request using the specified method and URL, with an optional progress bar.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
method
|
str
|
The HTTP method to use (e.g. 'GET', 'POST'). |
required |
url
|
str
|
The URL to send the request to. |
required |
**kwargs
|
any
|
Additional keyword arguments to pass to the underlying |
{}
|
Returns:
Type | Description |
---|---|
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 a number then progress bar will display assuming content length = progress.
Source code in ultralytics/hub/utils.py
ultralytics.hub.utils.smart_request
smart_request(
method,
url,
retry=3,
timeout=30,
thread=True,
code=-1,
verbose=True,
progress=False,
**kwargs
)
Makes an HTTP request using the 'requests' library, with exponential backoff retries up to a specified timeout.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
method
|
str
|
The HTTP method to use for the request. Choices are 'post' and 'get'. |
required |
url
|
str
|
The URL to make the request to. |
required |
retry
|
int
|
Number of retries to attempt before giving up. Default is 3. |
3
|
timeout
|
int
|
Timeout in seconds after which the function will give up retrying. Default is 30. |
30
|
thread
|
bool
|
Whether to execute the request in a separate daemon thread. Default is True. |
True
|
code
|
int
|
An identifier for the request, used for logging purposes. Default is -1. |
-1
|
verbose
|
bool
|
A flag to determine whether to print out to console or not. Default is True. |
True
|
progress
|
bool
|
Whether to show a progress bar during the request. Default is False. |
False
|
**kwargs
|
any
|
Keyword arguments to be passed to the requests function specified in method. |
{}
|
Returns:
Type | Description |
---|---|
Response
|
The HTTP response object. If the request is executed in a separate thread, returns None. |