我正在尝试使用 python SDK v2 删除 AzureML 模型,
但我找不到这样的功能。
这有点令人惊讶,因为 Web UI 中有这样的功能。
正在查看两者 azure.ai.ml.entities.Model
和azure.ai.ml.operations.ModelOperations
(定义所有 ml_client.models.<operation>
操作的类) - 找不到对它们下的删除操作的支持。
编辑2:
作为部分解决方案,这可以使用 SDK v1 来实现:
from azureml.core import Workspace, Model
workspace = ...
model = Model(workspace=workspace, name=name, version=version)
model.delete()
最佳答案
using Azure cli and python sdk I Deleted Azure ML model using python SDK 1.49.0
- 使用 Azure cli 我得到了相同的命令
- 添加 az 扩展后我能够找到删除命令
az extension add -n azure-cli-ml
az ml model delete --model-id <model_id> --workspace-name <workspace_name> --resource-group <resource_group> --subscription <subscription_id>
- 使用Python SDK
from azureml.core import Workspace, Model
# Replace with your AzureML workspace details
subscription_id = "your-subscription-id"
resource_group = "your-resource-group"
workspace_name = "your-workspace-name"
# Replace with your model name and version
model_name = "your-model-name"
model_version = 2
workspace = Workspace(subscription_id, resource_group, workspace_name)
# Get the model using the Model class
model = Model(workspace=workspace, name=model_name, version=model_version)
model = Model(workspace, name=model_name)
model_id = model.id
print("Model ID:", model_id)
# Delete the model
model.delete()
print("Model deleted successfully.")
关于python - 使用 python SDK v2 删除 AzureML 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75712901/