matrice.exported_model module#
- class matrice.exported_model.ExportedModel(session, model_export_id=None, model_export_name='')[source]#
Bases:
object
A class to handle operations related to model export within a project.
The ExportedModel class facilitates managing model export processes, including fetching summaries, listing available exported models, and performing evaluation tasks on optimized inferences.
- Parameters:
session (Session) – An active session object that holds project information such as the project ID and RPC client.
model_export_id (str, optional) – A unique identifier for the model export or inference optimization. Defaults to None.
model_export_name (str, optional) – The name of the model export or inference optimization. Defaults to an empty string.
- project_id#
The project ID associated with the current session.
- Type:
str
- model_export_id#
The unique identifier for the model export, provided at initialization or set later.
- Type:
str or None
- model_export_name#
The name of the model export, provided at initialization or set later.
- Type:
str
- rpc#
The RPC client used to make API requests.
- Type:
object
Example
>>> session = Session(account_number=account_number) >>> exported_model = ExportedModel(session=session, model_export_id="12345", model_export_name="sample_export") >>> print(exported_model.model_export_name) # Output: "sample_export"
- add_evaluation(id_dataset, dataset_version, split_types, is_gpu_required=True, is_pruned=False)[source]#
Add a new model evaluation using specified parameters.
- Parameters:
is_pruned (bool) – Whether the model is pruned.
id_dataset (str) – The ID of the dataset used for evaluation.
id_experiment (str) – The ID of the experiment associated with the model.
dataset_version (str) – The version of the dataset.
is_gpu_required (bool) – Whether the model requires GPU for inference.
split_types (list) – A list of split types used in the evaluation.
- Returns:
A tuple containing: - resp (dict): The API response object. - error (str or None): Error message if the API call failed, otherwise None. - message (str): Success or error message.
- Return type:
tuple
Example
>>> eval_result, err, msg = exported_model.add_evaluation( is_pruned=False, id_dataset="dataset123", id_experiment="experiment123", dataset_version="v1.0", is_gpu_required=True, split_types=["train", "test"]) >>> if err: >>> print(f"Error: {err}") >>> else: >>> print(f"Evaluation added: {eval_result}")
- delete()[source]#
Delete a model export.
- Returns:
A tuple containing: - resp (dict): The API response object. - error (str or None): Error message if the API call failed, otherwise None. - message (str): Success or error message.
- Return type:
tuple
Example
>>> result, err, msg = exported_model.delete() >>> if err: >>> print(f"Error: {err}") >>> else: >>> print(f"Model Export 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 = exported_model.download_model("model.pth") >>> if error: >>> print(f"Error: {error}") >>> else: >>> print(f"Model downloaded: {result}")
- get_details()[source]#
Retrieve details of the model export based on the model export ID or name.
This method fetches details by ID if available; otherwise, it attempts to fetch by name. Raises a ValueError if neither identifier is provided.
- Returns:
A tuple containing the model export details, error message (if any), and a status message.
- Return type:
tuple
- Raises:
ValueError – If neither ‘model_export_id’ nor ‘model_export_name’ is provided.
Example
>>> details, err, msg = exported_model.get_details() >>> if err: >>> print(f"Error: {err}") >>> else: >>> print(f"Model Export 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 = exported_model.get_model_download_path() >>> if error: >>> print(f"Error: {error}") >>> else: >>> print(f"Download path: {download_path}")
- get_evaluation_result(dataset_id, dataset_version, split_types)[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 (list) – The types of splits used for the evaluation.
- Returns:
A tuple with the evaluation result, error message, and status message.
- Return type:
tuple
Example
>>> eval_result, error, message = exported_model.get_evaluation_result("dataset123", "v1.0", ["train"]) >>> if error: >>> print(f"Error: {error}") >>> else: >>> print(f"Evaluation result: {eval_result}")
- get_prediction(image_path)[source]#
Tests a exported 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 = exported_model.get_prediction("/path/to/test_image.jpg") >>> print(result) {'test_result': 'success', 'confidence': 0.85}
- get_trained_model()[source]#
Fetch details of a model training associated with a specific export ID.
- Returns:
A tuple containing: - resp (dict): The API response object. - error (str or None): Error message if the API call failed, otherwise None. - message (str): Success or error message.
- Return type:
tuple
Example
>>> training_data, err, msg = exported_model.get_model_train_of_the_export() >>> if err: >>> print(f"Error: {err}") >>> else: >>> print(f"Model Training Data: {training_data}")
- rename(updated_name)[source]#
Update the name of a model export.
- Parameters:
updated_name (str) – The new name for the model export.
- Returns:
A tuple containing: - resp (dict): The API response object. - error (str or None): Error message if the API call failed, otherwise None. - message (str): Success or error message.
- Return type:
tuple
Example
>>> result, err, msg = exported_model.rename("NewModelExportName") >>> if err: >>> print(f"Error: {err}") >>> else: >>> print(f"Model Export Name Updated: {result}")