Starting your Amazon Lookout for Vision model - Amazon Lookout for Vision

Starting your Amazon Lookout for Vision model

Before you can use an Amazon Lookout for Vision model to detect anomalies, you must first start the model. You start a model by calling the StartModel API and passing the following:

  • ProjectName – The name of the project that contains the model that you want to start.

  • ModelVersion – The version of the model that you want to start.

  • MinInferenceUnits – The minimum number of inference units. For more information, see Running your trained Amazon Lookout for Vision model.

The Amazon Lookout for Vision console provides example code that you can use to start and stop a model.

Note

You are charged for the amount of the time that your model is running. To stop a running model, see Stopping your Amazon Lookout for Vision model.

Starting your model (console)

The Amazon Lookout for Vision console provides a AWS CLI command that you can use to start a model. After the model starts, you can start detecting anomalies in images. For more information, see Detecting anomalies in an image.

To start a model (console)

  1. If you haven't already done so, do the following:

    1. Create or update an IAM user with permissions to access Amazon Lookout for Vision. For more information, see Step 3: Set up permissions.

    2. Install and configure the AWS CLI and the AWS SDKs. For more information, see Step 5: Set up the AWS CLI and AWS SDKs.

  2. Open the Amazon Lookout for Vision console at https://console.aws.amazon.com/lookoutvision/.

  3. Choose Get started.

  4. In the left navigation pane, choose Projects.

  5. On the Projects resources page, choose the project that contains the trained model that you want to start.

  6. In the Models section, choose the model that you want to start.

  7. On the model's details page, choose the Use model tab.

  8. Under Code snippets choose AWS CLI commands.

  9. Copy the AWS CLI command that calls start-model.

  10. At the command prompt, enter the start-model command that you copied in the previous step.

  11. In the console, choose Models in the left navigation page.

  12. Check the Status column for the current status of the model, When the status is Hosted, you can use the model to detect anomalies in images. For more information, see Detecting anomalies in an image.

Starting your Amazon Lookout for Vision model (SDK)

You start a model by calling the StartModel operation.

A model might take a while to start. You can check the current status by calling DescribeModel. For more information, see Viewing your models.

To start your model (SDK)

  1. If you haven't already done so, do the following:

    1. Create or update an IAM user with permissions to access Amazon Lookout for Vision. For more information, see Step 3: Set up permissions.

    2. Install and configure the AWS CLI and the AWS SDKs. For more information, see Step 5: Set up the AWS CLI and AWS SDKs.

  2. Use the following example code to start a model.

    CLI

    Change the following values:

    • project-name to the name of the project that contains the model that you want to start.

    • model-version to the version of the model that you want to start.

    • --min-inference-units to the number of anomaly detection units that you want to use.

    aws lookoutvision start-model --project-name "project name"\ --model-version model version\ --min-inference-units number of units
    Python

    This code is taken from the AWS Documentation SDK examples GitHub repository. See the full example here.

    @staticmethod def start_model( lookoutvision_client, project_name, model_version, min_inference_units): """ Starts the hosting of a Lookout for Vision model. :param lookoutvision_client: A Boto3 Lookout for Vision client. :param project_name: The name of the project that contains the version of the model that you want to start hosting. :param model_version: The version of the model that you want to start hosting. :param min_inference_units: The number of inference units to use for hosting. """ try: logger.info( "Starting model version %s for project %s", model_version, project_name) lookoutvision_client.start_model( ProjectName=project_name, ModelVersion=model_version, MinInferenceUnits=min_inference_units) print("Starting hosting...") status = "" finished = False # Wait until hosted or failed. while finished is False: model_description = lookoutvision_client.describe_model( ProjectName=project_name, ModelVersion=model_version) status = model_description["ModelDescription"]["Status"] if status == "STARTING_HOSTING": logger.info("Host starting in progress...") time.sleep(10) continue if status == "HOSTED": logger.info("Model is hosted and ready for use.") finished = True continue logger.info("Model hosting failed and the model can't be used.") finished = True if status != "HOSTED": logger.error("Error hosting model: %s", status) raise Exception(f"Error hosting model: {status}") except ClientError: logger.exception("Couldn't host model.") raise
    Java V2

    This code is taken from the AWS Documentation SDK examples GitHub repository. See the full example here.

    /** * Starts hosting an Amazon Lookout for Vision model. Returns when the model has * started or if hosting fails. You are charged for the amount of time that * a model is hosted. To stop hosting a model, use the StopModel operation. * * @param lfvClient An Amazon Lookout for Vision client. * @param projectName The name of the project that contains the model that you * want to host. * @modelVersion The version of the model that you want to host. * @minInferenceUnits The number of inference units to use for hosting. * @return ModelDescription The description of the model, which includes the * model hosting status. */ public static ModelDescription startModel(LookoutVisionClient lfvClient, String projectName, String modelVersion, int minInferenceUnits) throws LookoutVisionException, InterruptedException { logger.log(Level.INFO, "Starting Model version {0} for project {1}.", new Object[] { modelVersion, projectName }); StartModelRequest startModelRequest = StartModelRequest.builder() .projectName(projectName) .modelVersion(modelVersion) .minInferenceUnits(minInferenceUnits) .build(); // Start hosting the model. lfvClient.startModel(startModelRequest); DescribeModelRequest describeModelRequest = DescribeModelRequest.builder() .projectName(projectName) .modelVersion(modelVersion) .build(); ModelDescription modelDescription = null; boolean finished = false; // Wait until model is hosted or failure occurs. do { modelDescription = lfvClient.describeModel(describeModelRequest).modelDescription(); switch (modelDescription.status()) { case HOSTED: logger.log(Level.INFO, "Model version {0} for project {1} is running.", new Object[] { modelVersion, projectName }); finished = true; break; case STARTING_HOSTING: logger.log(Level.INFO, "Model version {0} for project {1} is starting.", new Object[] { modelVersion, projectName }); TimeUnit.SECONDS.sleep(60); break; case HOSTING_FAILED: logger.log(Level.SEVERE, "Hosting failed for model version {0} for project {1}.", new Object[] { modelVersion, projectName }); finished = true; break; default: logger.log(Level.SEVERE, "Unexpected error when hosting model version {0} for project {1}: {2}.", new Object[] { projectName, modelVersion, modelDescription.status() }); finished = true; break; } } while (!finished); logger.log(Level.INFO, "Finished starting model version {0} for project {1} status: {2}", new Object[] { modelVersion, projectName, modelDescription.statusMessage() }); return modelDescription; }
  3. If the output of the code is Model is hosted and ready for use, you can use the model to detect anomalies in images. For more information, see Detecting anomalies in an image.