Reference for hub_sdk/modules/models.py
Note
This file is available at https://github.com/ultralytics/hub-sdk/blob/main/hub_sdk/modules/models.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
hub_sdk.modules.models.Models
Bases: CRUDClient
A class representing a client for interacting with Models through CRUD operations. This class extends the CRUDClient class and provides specific methods for working with Models.
Attributes:
Name | Type | Description |
---|---|---|
base_endpoint |
str
|
The base endpoint URL for the API, set to "models". |
hub_client |
ModelUpload
|
An instance of ModelUpload used for interacting with model uploads. |
id |
(str, None)
|
The unique identifier of the model, if available. |
data |
dict
|
A dictionary to store model data. |
metrics |
Placeholder for storing model metrics, if available after retrieval. |
Note
The 'id' attribute is set during initialization and can be used to uniquely identify a model. The 'data' attribute is used to store model data fetched from the API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_id
|
str
|
The unique identifier of the model. |
None
|
headers
|
dict
|
Headers to be included in API requests. |
None
|
Source code in hub_sdk/modules/models.py
create_model
Creates a new model with the provided data and sets the model ID for the current instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_data
|
dict
|
A dictionary containing the data for creating the model. |
required |
Returns:
Type | Description |
---|---|
None
|
The method does not return a value. |
Source code in hub_sdk/modules/models.py
delete
Delete the model resource represented by this instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hard
|
bool
|
If True, perform a hard (permanent) delete. |
False
|
Note
The 'hard' parameter determines whether to perform a soft delete (default) or a hard delete. In a soft delete, the model might be marked as deleted but retained in the system. In a hard delete, the model is permanently removed from the system.
Returns:
Type | Description |
---|---|
Optional[Response]
|
Response object from the delete request, or None if delete fails. |
Source code in hub_sdk/modules/models.py
export
Export to Ultralytics HUB.
Args: format (str): Export format here. Here are supported export formats
Returns:
Type | Description |
---|---|
Optional[Response]
|
Response object from the export request, or None if export fails. |
Source code in hub_sdk/modules/models.py
get_architecture
Get the architecture name of the model.
Returns:
Type | Description |
---|---|
Optional[str]
|
The architecture name followed by '.yaml' or None if not available. |
get_data
Retrieves data for the current model instance.
If a valid model ID has been set, it sends a request to fetch the model data and stores it in the instance. If no model ID has been set, it logs an error message.
Returns:
Type | Description |
---|---|
None
|
The method does not return a value. |
Source code in hub_sdk/modules/models.py
get_dataset_url
Get the dataset URL associated with the model.
Returns:
Type | Description |
---|---|
Optional[str]
|
The URL of the dataset or None if not available. |
get_metrics
Get metrics to of model.
Returns:
Type | Description |
---|---|
(list(dict), optional)
|
The list of metrics objects, or None if it fails. |
Source code in hub_sdk/modules/models.py
get_weights_url
Get the URL of the model weights.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
weight
|
str
|
Type of weights to retrieve. |
'best'
|
Returns:
Type | Description |
---|---|
Optional[str]
|
The URL of the specified weights or None if not available. |
Source code in hub_sdk/modules/models.py
has_best_weights
Check if the model has best weights saved.
Returns:
Type | Description |
---|---|
bool
|
True if best weights available, False otherwise. |
is_custom
Check if the model is custom.
Returns:
Type | Description |
---|---|
bool
|
True if custom, False otherwise. |
is_pretrained
Check if the model is pretrained.
Returns:
Type | Description |
---|---|
bool
|
True if pretrained, False otherwise. |
is_resumable
Check if the model training can be resumed.
Returns:
Type | Description |
---|---|
bool
|
True if resumable, False otherwise. |
is_trained
Check if the model is trained.
Returns:
Type | Description |
---|---|
bool
|
True if trained, False otherwise. |
predict
Predict to Ultralytics HUB.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
str
|
The path to the image file. |
required |
config
|
dict
|
A configuration for the prediction (JSON). |
required |
Returns:
Type | Description |
---|---|
Optional[Response]
|
Response object from the predict request, or None if upload fails. |
Source code in hub_sdk/modules/models.py
start_heartbeat
Starts sending heartbeat signals to a remote hub server.
This method initiates the sending of heartbeat signals to a hub server in order to indicate the continued availability and health of the client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
interval
|
int
|
The time interval, in seconds, between consecutive heartbeats. |
60
|
Returns:
Type | Description |
---|---|
None
|
The method does not return a value. |
Note
Heartbeats are essential for maintaining a connection with the hub server and ensuring that the client remains active and responsive.
Source code in hub_sdk/modules/models.py
stop_heartbeat
Stops sending heartbeat signals to a remote hub server.
This method terminates the sending of heartbeat signals to the hub server, effectively signaling that the client is no longer available or active.
Returns:
Type | Description |
---|---|
None
|
The method does not return a value. |
Note
Stopping heartbeats should be done carefully, as it may result in the hub server considering the client as disconnected or unavailable.
Source code in hub_sdk/modules/models.py
update
Update the model resource represented by this instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
dict
|
The updated data for the model resource. |
required |
Returns:
Type | Description |
---|---|
Optional[Response]
|
Response object from the update request, or None if update fails. |
Source code in hub_sdk/modules/models.py
upload_metrics
Upload model metrics to Ultralytics HUB.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metrics
|
dict
|
|
required |
Returns:
Type | Description |
---|---|
Optional[Response]
|
Response object from the upload metrics request, or None if it fails. |
Source code in hub_sdk/modules/models.py
upload_model
upload_model(
epoch: int,
weights: str,
is_best: bool = False,
map: float = 0.0,
final: bool = False,
) -> Optional[Response]
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
|
Returns:
Type | Description |
---|---|
Optional[Response]
|
Response object from the upload request, or None if upload fails. |
Source code in hub_sdk/modules/models.py
hub_sdk.modules.models.ModelList
Bases: PaginatedList
Provides a paginated list interface for managing and querying models from the Ultralytics HUB API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
page_size
|
int
|
The number of items to request per page. |
None
|
public
|
bool
|
Whether the items should be publicly accessible. |
None
|
headers
|
dict
|
Headers to be included in API requests. |
None
|