Reference for hub_sdk/base/server_clients.py
Note
This file is available at https://github.com/ultralytics/hub-sdk/blob/main/hub_sdk/base/server_clients.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
hub_sdk.base.server_clients.ModelUpload
Bases: APIClient
Manages uploading and exporting model files and metrics to Ultralytics HUB and heartbeat updates.
Source code in hub_sdk/base/server_clients.py
_handle_signal
Handle kill signals and prevent heartbeats from being sent on Colab after termination.
This method does not use frame, it is included as it is passed by signal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
signum
|
int
|
Signal number. |
required |
frame
|
Any
|
The current stack frame (not used in this method). |
required |
Returns:
Type | Description |
---|---|
None
|
The method does not return a value. |
Source code in hub_sdk/base/server_clients.py
_register_signal_handlers
Register signal handlers for SIGTERM and SIGINT signals to gracefully handle termination.
Returns:
Type | Description |
---|---|
None
|
The method does not return a value. |
Source code in hub_sdk/base/server_clients.py
_start_heartbeats
Begin a threaded heartbeat loop to report the agent's status to Ultralytics HUB.
This method initiates a threaded loop that periodically sends heartbeats to Ultralytics HUB to report the status of the agent. Heartbeats are sent at regular intervals as defined in the 'rate_limits' dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_id
|
str
|
The unique identifier of the model associated with the agent. |
required |
interval
|
int
|
The time interval, in seconds, between consecutive heartbeats. |
required |
Returns:
Type | Description |
---|---|
None
|
The method does not return a value. |
Source code in hub_sdk/base/server_clients.py
_stop_heartbeats
Stop the threaded heartbeat loop.
This method stops the threaded loop responsible for sending heartbeats to Ultralytics HUB. It sets the 'alive' flag to False, which will cause the loop in '_start_heartbeats' to exit.
Returns:
Type | Description |
---|---|
None
|
The method does not return a value. |
Source code in hub_sdk/base/server_clients.py
export
Export a file for a specific entity.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id
|
str
|
The unique identifier of the entity to which the file is being exported. |
required |
format
|
str
|
Path to the file to be Exported. |
required |
Returns:
Type | Description |
---|---|
Optional[Response]
|
Response object from the export request, or None if it fails. |
Source code in hub_sdk/base/server_clients.py
predict
Perform a prediction using the specified image and configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id
|
str
|
Unique identifier for the prediction request. |
required |
image
|
str
|
Image path for prediction. |
required |
config
|
dict
|
Configuration parameters for the prediction. |
required |
Returns:
Type | Description |
---|---|
Optional[Response]
|
Response object from the predict request, or None if upload fails. |
Source code in hub_sdk/base/server_clients.py
upload_metrics
Upload a file for a specific entity.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id
|
str
|
The unique identifier of the entity to which the file is being uploaded. |
required |
data
|
dict
|
The metrics data to upload. |
required |
Returns:
Type | Description |
---|---|
Optional[Response]
|
Response object from the upload_metrics request, or None if it fails. |
Source code in hub_sdk/base/server_clients.py
upload_model
Upload a model checkpoint to Ultralytics HUB.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
epoch
|
int
|
The current training epoch. |
required |
weights
|
str
|
Path to the model weights file. |
required |
is_best
|
bool
|
Indicates if the current model is the best one so far. |
False
|
map
|
float
|
Mean average precision of the model. |
0.0
|
final
|
bool
|
Indicates if the model is the final model after training. |
False
|
Source code in hub_sdk/base/server_clients.py
hub_sdk.base.server_clients.ProjectUpload
Bases: APIClient
Handle project file uploads to Ultralytics HUB via API requests.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
headers
|
dict
|
The headers to use for API requests. |
required |
Source code in hub_sdk/base/server_clients.py
upload_image
Upload a project file to the hub.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id
|
str
|
The ID of the dataset to upload. |
required |
file
|
str
|
The path to the dataset file to upload. |
required |
Returns:
Type | Description |
---|---|
Optional[Response]
|
Response object from the upload image request, or None if it fails. |
Source code in hub_sdk/base/server_clients.py
hub_sdk.base.server_clients.DatasetUpload
Bases: APIClient
Manages uploading dataset files to Ultralytics HUB via API requests.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
headers
|
dict
|
The headers to use for API requests. |
required |
Source code in hub_sdk/base/server_clients.py
upload_dataset
Upload a dataset file to the hub.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id
|
str
|
The ID of the dataset to upload. |
required |
file
|
str
|
The path to the dataset file to upload. |
required |
Returns:
Type | Description |
---|---|
Optional[Response]
|
Response object from the upload dataset request, or None if it fails. |
Source code in hub_sdk/base/server_clients.py
hub_sdk.base.server_clients.is_colab
Check if the current script is running inside a Google Colab notebook.
Returns:
Type | Description |
---|---|
bool
|
True if running inside a Colab notebook, False otherwise. |