终止支持通知:2025年10月31日, AWS 将停止对亚马逊 Lookout for Vision 的支持。2025 年 10 月 31 日之后,你将无法再访问 Lookout for Vision 主机或 Lookout for Vision 资源。如需更多信息,请访问此博客文章。
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
停止您的 Amazon Lookout for Vision 模型
要停止正在运行的模型,您可以调用 StopModel
操作并传递以下项:
项目:包含要停止的模型的项目的名称。
ModelVersion:要停止的模型版本。
Amazon Lookout for Vision 控制台提供了示例代码,可用于停止模型。
停止您的模型(控制台)
执行以下过程中的步骤,可以使用控制台停止您的模型。
停止您的模型(控制台)
-
安装并配置 AWS CLI 和 AWS SDK(如果尚未如此)。有关更多信息,请参阅 第 4 步:设置 AWS CLI 和 AWS SDKs。
打开 Amazon Lookout for Vision 控制台,网址为 https://console.aws.amazon.com/lookoutvision/。
选择开始使用。
在左侧导航窗格中,选择项目。
在项目资源页面上,选择包含要停止的运行中模型的项目。
在模型部分,选择要停止的模型。
在模型的详细信息页面上,选择使用模型,然后选择将 API 集成到云。
在 Amazon CLI 命令下,复制用于调用 stop-model
的 AWS CLI 命令。
-
在命令提示符处,输入您在上一步中复制的 stop-model
命令。如果您使用 lookoutvision
配置文件来获取凭证,请添加 --profile
lookoutvision-access
参数。
在控制台,选择左侧导航页面中的模型。
查看状态列以了解模型的当前状态。当状态列的值为训练完成时,表示模型已停止。
停止您的 Amazon Lookout for Vision 模型 (SDK)
您可以通过调用 StopModel 操作来停止模型。
模型可能需要一段时间才能停止。要检查当前状态,请使用 DescribeModel
。
停止您的模型 (SDK)
-
安装并配置 AWS CLI 和 AWS SDK(如果尚未如此)。有关更多信息,请参阅 第 4 步:设置 AWS CLI 和 AWS SDKs。
使用以下示例代码停止正在运行的模型。
- CLI
-
更改以下值:
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;
}