终止支持通知:2025年10月31日, AWS 将停止对亚马逊 Lookout for Vision 的支持。2025 年 10 月 31 日之后,你将无法再访问 Lookout for Vision 主机或 Lookout for Vision 资源。如需更多信息,请访问此博客文章。
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
删除模型
您可以使用控制台或使用 DeleteModel
操作,删除模型的版本。您无法删除正在运行或正在训练的模型版本。
如果模型版本正在运行,请先使用 StopModel
操作停止该模型版本。有关更多信息,请参阅 停止您的 Amazon Lookout for Vision 模型。如果模型正在训练,请等到训练完成后再删除模型。
删除模型可能需要几秒钟。要确定模型是否已被删除,请调用ListProjects并检查Models
数组中是否有 model (ModelVersion
) 的版本。
删除模型(控制台)
执行以下步骤,可以从控制台中删除模型。
删除模型 (SDK)
通过以下过程,可使用 DeleteModel
操作删除模型。
要删除模型 (SDK)
-
如果您尚未这样做,请安装并配置 AWS CLI 和 AWS SDKs。有关更多信息,请参阅 第 4 步:设置 AWS CLI 和 AWS SDKs。
使用以下示例代码删除模型。
- CLI
-
更改以下值:
aws lookoutvision delete-model --project-name project name
\
--model-version model version
\
--profile lookoutvision-access
- Python
-
此代码取自 AWS 文档SDK示例 GitHub 存储库。请在此处查看完整示例。
@staticmethod
def delete_model(lookoutvision_client, project_name, model_version):
"""
Deletes a Lookout for Vision model. The model must first be stopped and can't
be in training.
:param lookoutvision_client: A Boto3 Lookout for Vision client.
:param project_name: The name of the project that contains the desired model.
:param model_version: The version of the model that you want to delete.
"""
try:
logger.info("Deleting model: %s", model_version)
lookoutvision_client.delete_model(
ProjectName=project_name, ModelVersion=model_version
)
model_exists = True
while model_exists:
response = lookoutvision_client.list_models(ProjectName=project_name)
model_exists = False
for model in response["Models"]:
if model["ModelVersion"] == model_version:
model_exists = True
if model_exists is False:
logger.info("Model deleted")
else:
logger.info("Model is being deleted...")
time.sleep(2)
logger.info("Deleted Model: %s", model_version)
except ClientError:
logger.exception("Couldn't delete model.")
raise
- Java V2
-
此代码取自 AWS 文档SDK示例 GitHub 存储库。请在此处查看完整示例。
/**
* Deletes an Amazon Lookout for Vision model.
*
* @param lfvClient An Amazon Lookout for Vision client. Returns after the model is deleted.
* @param projectName The name of the project that contains the model that you want to delete.
* @param modelVersion The version of the model that you want to delete.
* @return void
*/
public static void deleteModel(LookoutVisionClient lfvClient,
String projectName,
String modelVersion) throws LookoutVisionException, InterruptedException {
DeleteModelRequest deleteModelRequest = DeleteModelRequest.builder()
.projectName(projectName)
.modelVersion(modelVersion)
.build();
lfvClient.deleteModel(deleteModelRequest);
boolean deleted = false;
do {
ListModelsRequest listModelsRequest = ListModelsRequest.builder()
.projectName(projectName)
.build();
// Get a list of models in the supplied project.
ListModelsResponse response = lfvClient.listModels(listModelsRequest);
ModelMetadata modelMetadata = response.models().stream()
.filter(model -> model.modelVersion().equals(modelVersion)).findFirst()
.orElse(null);
if (modelMetadata == null) {
deleted = true;
logger.log(Level.INFO, "Deleted: Model version {0} of project {1}.",
new Object[] { modelVersion, projectName });
} else {
logger.log(Level.INFO, "Not yet deleted: Model version {0} of project {1}.",
new Object[] { modelVersion, projectName });
TimeUnit.SECONDS.sleep(60);
}
} while (!deleted);
}