支援終止通知:2025 年 10 月 31 日, AWS 將停止支援 Amazon Lookout for Vision。2025 年 10 月 31 日之後,您將無法再存取 Lookout for Vision 主控台或 Lookout for Vision 資源。如需詳細資訊,請造訪此部落格文章。
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
停止您的 Amazon Lookout for Vision 模型
若要停止執行中的模型,請呼叫 StopModel
操作並傳遞以下內容:
Amazon Lookout for Vision 主控台提供範例程式碼,可用來停止模型。
停止模型 (主控台)
執行下列程序中的步驟,以使用 主控台停止模型。
停止模型 (主控台)
-
如果您尚未這麼做,請安裝並設定 AWS CLI 和 AWS SDKs。如需詳細資訊,請參閱步驟 4:設定 AWS CLI 和 SDK AWS SDKs。
開啟 Amazon Lookout for Vision 主控台,網址為 https://https://console.aws.amazon.com/lookoutvision/。
選擇開始使用。
在左側導覽視窗中,選擇專案。
在專案資源頁面上,選擇包含您要停止之執行中模型的專案。
在 模型 的區域中,選擇您要停止的模型。
在模型的詳細資訊頁面上,選擇使用模型,然後選擇將 API 整合到雲端。
在 AWS CLI 命令下,複製呼叫 的 AWS CLI 命令stop-model
。
-
在命令提示中,輸入您在上一步驟中複製的 stop-model
命令。如果您使用lookoutvision
設定檔來取得登入資料,請新增 --profile lookoutvision-access
參數。
在主控台的左側導覽頁面中選擇模型。
檢查狀態欄,了解模型的目前狀態。當狀態資料欄值為訓練完成時,模型已停止。
停止您的 Amazon Lookout for Vision 模型 (SDK)
您可以透過呼叫 StopModel 操作來停止模型。
模型可能需要一段時間才能停止。若要檢查目前狀態,請使用 DescribeModel
。
停止模型 (SDK)
-
如果您尚未這麼做,請安裝並設定 AWS CLI 和 AWS SDKs。如需詳細資訊,請參閱步驟 4:設定 AWS CLI 和 SDK AWS SDKs。
使用下列範例程式碼來停止執行中的模型。
- CLI
-
變更下列值:
aws lookoutvision stop-model --project-name "project name
"\
--model-version model version
\
--profile lookoutvision-access
- Python
-
此程式碼取自 AWS 文件開發套件範例 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 文件開發套件範例 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;
}