matrice.models module#
- class matrice.models.Model(session, model_id=None, model_name='')[source]#
Bases:
object
The Model class provides methods for interacting with models in a project, including fetching summaries, listing models, and performing evaluations.
- Parameters:
session (Session) – A session object containing the project ID and RPC client.
model_id (str, optional) – The unique identifier for the model (default is None).
model_name (str, optional) – The name of the model (default is an empty string).
Example
>>> session = Session(project_id="project123") >>> model = Model(session, model_id="model789")
- add_evaluation(dataset_id, dataset_version, split_types, is_pruned=False, is_gpu_required=False)[source]#
Add a new model evaluation using specified parameters.
- Parameters:
dataset_id (str) – The ID of the dataset.
dataset_version (str) – The version of the dataset.
split_types (list) – The split types used in the evaluation.
is_pruned (bool, optional) – Whether the model is pruned (default is False).
is_gpu_required (bool, optional) – Whether the model requires a GPU (default is False).
- Returns:
A tuple with the evaluation result, error message, and status message.
- Return type:
tuple
Example
>>> result, error, message = model.add_model_eval( >>> id_dataset="dataset123", >>> dataset_version="v1.0", >>> split_types=["train", "val"], >>> )
- delete()[source]#
Delete the trained model.
- Returns:
A tuple with the deletion result, error message, and status message.
- Return type:
tuple
Example
>>> result, error, message = model.delete() >>> if error: >>> print(f"Error: {error}") >>> else: >>> print(f"Model deleted: {result}")
- download_model(file_name)[source]#
Download the specified model type to a local file. There are 2 types of model types: trained and exported.
- Parameters:
file_name (str) – The name of the file to save the downloaded model.
model_type (str) – The type of the model to download. Default is “trained”.
- Returns:
A tuple with the download status, error message, and status message.
- Return type:
tuple
Example
>>> result, error, message = model.download_model("model.pth", model_type="trained") >>> if error: >>> print(f"Error: {error}") >>> else: >>> print(f"Model downloaded: {result}")
- get_details()[source]#
Get model details based on the provided ID or name.
- Returns:
A tuple containing the model details, error message, and status message.
- Return type:
tuple
Example
>>> details, error, message = model.get_details() >>> if error: >>> print(f"Error: {error}") >>> else: >>> print(f"Model details: {details}")
- get_download_path()[source]#
Get the download path for the specified model type. There are 2 types of model types: trained and exported.
- Parameters:
model_type (str) – The type of the model to download.
- Returns:
A tuple with the download path, error message, and status message.
- Return type:
tuple
Example
>>> download_path, error, message = model.get_model_download_path("trained") >>> if error: >>> print(f"Error: {error}") >>> else: >>> print(f"Download path: {download_path}")
- get_eval_result(dataset_id, dataset_version, split_type)[source]#
Fetch the evaluation result of a trained model using a specific dataset version and split type.
- Parameters:
dataset_id (str) – The ID of the dataset.
dataset_version (str) – The version of the dataset.
split_type (str) – The type of split used for the evaluation.
- Returns:
A tuple with the evaluation result, error message, and status message.
- Return type:
tuple
Example
>>> eval_result, error, message = model.get_eval_result("dataset123", "v1.0", "train") >>> if error: >>> print(f"Error: {error}") >>> else: >>> print(f"Evaluation result: {eval_result}")
- get_model_training_logs()[source]#
Fetch training logs for the specified model.
This method retrieves the logs of the training epochs for a model, including both training and validation metrics such as losses and accuracy.
- Returns:
A tuple containing: - A dictionary with the response from the RPC call. - An error message if the request fails. - A success message if the request succeeds.
- Return type:
tuple
Example
>>> response, error, message = model_logging.get_model_training_logs() >>> if error: >>> print(f"Error: {error}") >>> else: >>> print(f"Success: {message}")
- get_prediction(image_path)[source]#
Tests a trained model for a given image.
Parameters:#
- image_pathstr
The path to the image for testing.
Returns:#
: tuple:
A tuple consisting of (result, error, message) with the test results.
Example:#
>>> result, error, message = model.test_model("/path/to/test_image.jpg") >>> print(result) {'test_result': 'success', 'confidence': 0.85}
- model_test(model_type='trained')[source]#
Fetch information about the deployment server for a specific model.
- Parameters:
model_train_id (str) – The ID of the model training instance.
model_type (str) – The type of model (e.g., ‘trained’, ‘exported’).
- Returns:
A tuple containing three elements: - API response (dict): The raw response from the API. - error_message (str or None): Error message if an error occurred, None otherwise. - status_message (str): A status message indicating success or failure.
- Return type:
tuple
Examples
>>> resp, err, msg = model.model_test("trained") >>> if err: >>> print(f"Error: {err}") >>> else: >>> print(f"Deployment server details : {resp}")
- plot_epochs_losses()[source]#
Plot training and validation losses over epochs.
This method generates two subplots: one for the training losses and one for the validation losses, displaying how these metrics evolve over the epochs.
- Return type:
None
Example
>>> model_logging.plot_epochs_losses()
- plot_epochs_metrics()[source]#
Plot training and validation metrics (excluding losses) over epochs.
This method generates subplots for each non-loss metric, such as accuracy, showing how these metrics change during training epochs for both training and validation splits.
- Return type:
None
Example
>>> model_logging.plot_epochs_metrics()
- plot_eval_results()[source]#
Plot the evaluation results for the model.
Example
>>> model.plot_eval_results()
- rename(name)[source]#
Update the name of the trained model.
- Parameters:
name (str) – The new name for the trained model.
- Returns:
A tuple with the update result, error message, and status message.
- Return type:
tuple
Example
>>> result, error, message = model.rename("NewModelName") >>> if error: >>> print(f"Error: {error}") >>> else: >>> print(f"Model name updated: {result}")