使用Google Cloud AutoML API的ListOperations方法来检索所有AutoML训练操作,然后获取其项数并检查是否已达到了AutoML Training items limit的限制。以下是示例Python代码:
from google.cloud import automl_v1beta1
# Create a client
client = automl_v1beta1.AutoMlClient()
# List all the operations for the project
project_id = 'your-project-id'
operations = client.transport.list_operations(
f"projects/{project_id}/locations/us-central1",
filter_='metadata.create_time'
)
# Count operations
training_items = 0
for operation in operations:
# Check if it's a "CreateModel" or "ImportData" operation
if 'create_model' in operation.metadata and \
operation.metadata.create_model.operatoin_metadata.is_cancelled == False:
# Count input examples
training_items += operation.metadata.create_model.dataset_id.split('/').pop() or 0
elif 'import_data' in operation.metadata and \
operation.metadata.import_data.operation_metadata.is_cancelled == False:
# Count input examples
training_items += operation.metadata.import_data.dataset_id.split('/').pop() or 0
# check if the limit is reached
if training_items >= 500:
print("AutoML Training items limit reached.")