停止您的亞馬遜 Lookout for Vision 模型 - Amazon Lookout for Vision

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

停止您的亞馬遜 Lookout for Vision 模型

要停止正在運行的模型,請調用StopModel操作並傳遞以下內容:

  • 專案 (Project) — 包含您要停止之模型的專案名稱。

  • ModelVersion— 您要停止的模型版本。

Amazon 觀察視覺主控台提供可用於停止模型的範例程式碼。

注意

您需支付模型執行時間的費用。

停止您的模型(控制台)

執行下列程序中的步驟,使用控制台停止模型。

若要停止您的模型 (主控台)
  1. 如果您尚未這樣做,請安裝並設定AWS CLI和 AWS SDK。如需詳細資訊,請參閱步驟 4:設定 AWS CLI 和 AWS 軟體開發套件

  2. 打開亞馬遜 Lookout for Vision 控制台 https://console.aws.amazon.com/lookoutvision/.

  3. 選擇 Get started (開始使用)。

  4. 在左側導覽窗格中,選擇 [專案]。

  5. 在 [專案資源] 頁面上,選擇包含您要停止的執行中模型的專案。

  6. 在「模」區段中,選擇您要停止的模型。

  7. 在模型的詳細資料頁面上,選擇 [使用模型],然後選擇 [將 API 整合至雲端]。

  8. AWS CLI 命令下,複製呼叫的 AWS CLI 命令stop-model

  9. 於指令提示下,輸入您在上一個步驟中複製的stop-model指令。如果您使用lookoutvision設定檔取得認證,請新增--profile lookoutvision-access參數。

  10. 在主控台中,選擇左側導覽頁面中的 [模型]。

  11. 檢查「狀」(Status) 欄以瞭解模型的目前狀態。當「狀態」欄值為「訓練完成」時,模型已停止。

停止您的亞馬遜 Lookout for Vision 模型(SDK)

您可以呼叫StopModel作業來停止模型。

模型可能需要一段時間才能停止。若要檢查目前狀態,請使用DescribeModel

若要停止您的模型 (SDK)
  1. 如果您尚未這樣做,請安裝並設定AWS CLI和 AWS SDK。如需詳細資訊,請參閱步驟 4:設定 AWS CLI 和 AWS 軟體開發套件

  2. 使用下列範例程式碼來停止執行中的模型。

    CLI

    變更下列值:

    • project-name到包含要停止的模型的項目的名稱。

    • model-version到您要停止的模型版本。

    aws lookoutvision stop-model --project-name "project name"\ --model-version model version \ --profile lookoutvision-access
    Python

    此代碼取自AWS文檔 SDK 示例 GitHub 存儲庫。請參閱此處的完整範例。

    @staticmethod def stop_model(lookoutvision_client, project_name, model_version): """ Stops a running 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 stop hosting. :param model_version: The version of the model that you want to stop hosting. """ try: logger.info("Stopping model version %s for %s", model_version, project_name) response = lookoutvision_client.stop_model( ProjectName=project_name, ModelVersion=model_version ) logger.info("Stopping hosting...") status = response["Status"] finished = False # Wait until stopped 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 == "STOPPING_HOSTING": logger.info("Host stopping in progress...") time.sleep(10) continue if status == "TRAINED": logger.info("Model is no longer hosted.") finished = True continue logger.info("Failed to stop model: %s ", status) finished = True if status != "TRAINED": logger.error("Error stopping model: %s", status) raise Exception(f"Error stopping model: {status}") except ClientError: logger.exception("Couldn't stop hosting model.") raise
    Java V2

    此代碼取自AWS文檔 SDK 示例 GitHub 存儲庫。請參閱此處的完整範例。

    /** * Stops the hosting an Amazon Lookout for Vision model. Returns when model has * stopped or if hosting fails. * * @param lfvClient An Amazon Lookout for Vision client. * @param projectName The name of the project that contains the model that you * want to stop hosting. * @modelVersion The version of the model that you want to stop hosting. * @return ModelDescription The description of the model, which includes the * model hosting status. */ public static ModelDescription stopModel(LookoutVisionClient lfvClient, String projectName, String modelVersion) throws LookoutVisionException, InterruptedException { logger.log(Level.INFO, "Stopping Model version {0} for project {1}.", new Object[] { modelVersion, projectName }); StopModelRequest stopModelRequest = StopModelRequest.builder() .projectName(projectName) .modelVersion(modelVersion) .build(); // Stop hosting the model. lfvClient.stopModel(stopModelRequest); DescribeModelRequest describeModelRequest = DescribeModelRequest.builder() .projectName(projectName) .modelVersion(modelVersion) .build(); ModelDescription modelDescription = null; boolean finished = false; // Wait until model is stopped or failure occurs. do { modelDescription = lfvClient.describeModel(describeModelRequest).modelDescription(); switch (modelDescription.status()) { case TRAINED: logger.log(Level.INFO, "Model version {0} for project {1} has stopped.", new Object[] { modelVersion, projectName }); finished = true; break; case STOPPING_HOSTING: logger.log(Level.INFO, "Model version {0} for project {1} is stopping.", new Object[] { modelVersion, projectName }); TimeUnit.SECONDS.sleep(60); break; default: logger.log(Level.SEVERE, "Unexpected error when stopping model version {0} for project {1}: {2}.", new Object[] { projectName, modelVersion, modelDescription.status() }); finished = true; break; } } while (!finished); logger.log(Level.INFO, "Finished stopping model version {0} for project {1} status: {2}", new Object[] { modelVersion, projectName, modelDescription.statusMessage() }); return modelDescription; }