本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
刪除模型
您可以使用控制台或使用DeleteModel
操作來刪除模型的版本。您無法刪除正在執行或正在訓練的模型版本。
如果模型正在執行版本,請先使用該StopModel
作業停止模型版本。如需詳細資訊,請參閱停止您的亞馬遜 Lookout for Vision 模型。如果模型正在訓練,請等到完成後再刪除模型。
刪除模型可能需要幾秒鐘的時間。要確定模型是否已被刪除,請調用ListProjects並檢查 model (ModelVersion
) 的版本是否在Models
數組中。
刪除模型(控制台)
執行下列步驟,從主控台刪除模型。
刪除模型(控制台)
打開亞馬遜 Lookout for Vision 控制台 https://console.aws.amazon.com/lookoutvision/.
選擇 Get started (開始使用)。
在左側導覽窗格中,選擇 [專案]。
在「專案」頁面上,選取包含您要刪除之模型的專案。
在左側導覽窗格中選擇 Models (模型)。
在模型視圖中,選擇要刪除的模型的單選按鈕。
在頁面頂端,選擇 Delete (刪除)。
在「刪除」對話方塊中,輸入 delete 以確認您要刪除模型。
選擇刪除模型以刪除模型。
刪除模型 (SDK)
使用下列步驟來透過DeleteModel
操作刪除模型。
若要刪除模型 (SDK)
-
如果您尚未這樣做,請安裝並設定AWS CLI和 AWS SDK。如需詳細資訊,請參閱步驟 4:設定 AWS CLI 和 AWS 軟體開發套件。
使用下列範例程式碼來刪除模型。
- 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);
}