viam.app.ml_training_client

Module Contents

Classes

MLTrainingClient

gRPC client for working with ML training jobs.

Attributes

LOGGER

viam.app.ml_training_client.LOGGER
class viam.app.ml_training_client.MLTrainingClient(channel: grpclib.client.Channel, metadata: Mapping[str, str])[source]

gRPC client for working with ML training jobs.

Constructor is used by ViamClient to instantiate relevant service stubs. Calls to MLTrainingClient methods should be made through ViamClient.

Establish a Connection:

import asyncio

from viam.rpc.dial import DialOptions, Credentials
from viam.app.viam_client import ViamClient


async def connect() -> ViamClient:
    # Replace "<API-KEY>" (including brackets) with your API key and "<API-KEY-ID>" with your API key ID
    dial_options = DialOptions.with_api_key("<API-KEY>", "<API-KEY-ID>")
    return await ViamClient.create_from_dial_options(dial_options)


async def main():

    # Make a ViamClient
    viam_client = await connect()
    # Instantiate an MLTrainingClient to run ML training client API methods on
    ml_training_client = viam_client.ml_training_client

    viam_client.close()

if __name__ == '__main__':
    asyncio.run(main())
async submit_training_job(org_id: str, dataset_id: str, model_name: str, model_version: str, model_type: viam.proto.app.mltraining.ModelType.ValueType, tags: List[str]) str[source]

Submit a training job.

Parameters:
  • org_id (str) – the id of the org to submit the training job to

  • dataset_id (str) – the id of the dataset

  • model_name (str) – the model name

  • model_version (str) – the model version

  • model_type (ModelType.ValueType) – the model type

  • tags (List[str]) – the tags

Returns:

the id of the training job

Return type:

str

async submit_custom_training_job(org_id: str, dataset_id: str, registry_item_id: str, model_name: str, model_version: str) str[source]

Submit a custom training job.

Parameters:
  • org_id (str) – the id of the org to submit the training job to

  • dataset_id (str) – the id of the dataset

  • registry_item_id (List[str]) – the id of the registry item

  • model_name (str) – the model name

  • model_version (str) – the model version

Returns:

the id of the training job

Return type:

str

async get_training_job(id: str) viam.proto.app.mltraining.TrainingJobMetadata[source]

Gets training job data.

job_metadata = await ml_training_client.get_training_job(
    id="INSERT YOUR JOB ID")
Parameters:

id (str) – the id of the requested training job.

Returns:

training job data.

Return type:

viam.proto.app.mltraining.TrainingJobMetadata

async list_training_jobs(org_id: str, training_status: viam.proto.app.mltraining.TrainingStatus.ValueType | None = None) List[viam.proto.app.mltraining.TrainingJobMetadata][source]

Returns training job data for all jobs within an org.

jobs_metadata = await ml_training_client.list_training_jobs(
    org_id="INSERT YOUR ORG ID")

first_job_id = jobs_metadata[1].id
Parameters:
  • org_id (str) – the id of the org to request training job data from.

  • training_status (Optional[TrainingStatus]) – status of training jobs to filter the list by. If unspecified, all training jobs will be returned.

Returns:

a list of training job data.

Return type:

List[viam.proto.app.mltraining.TrainingJobMetadata]

async cancel_training_job(id: str) None[source]

Cancels the specified training job.

await ml_training_client.cancel_training_job(
    id="INSERT YOUR JOB ID")
Parameters:

id (str) – the id of the job to be canceled.

Raises:

GRPCError – if no training job exists with the given id.

async delete_completed_training_job(id: str) None[source]

Delete a completed training job from the database, whether the job succeeded or failed :param id: the id of the training job :type id: str