D'autres AWS SDK exemples sont disponibles dans le GitHub dépôt AWS Doc SDK Examples.
Les traductions sont fournies par des outils de traduction automatique. En cas de conflit entre le contenu d'une traduction et celui de la version originale en anglais, la version anglaise prévaudra.
À utiliser DeleteModel
avec un AWS SDK
L'exemple de code suivant montre comment utiliserDeleteModel
.
Pour plus d'informations, consultez la section Suppression d'un modèle.
- Python
-
- SDKpour Python (Boto3)
-
class Models:
@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