Se usó la API de Cloud Translation para traducir esta página.
Switch to English

Enumera modelos

Crear una lista de modelos existentes

Muestra de código

Java

/**
 * Demonstrates using the AutoML client to list all models.
 *
 * @param projectId the Id of the project.
 * @param computeRegion the Region name.
 * @param filter the filter expression.
 * @throws IOException on Input/Output errors.
 */
public static void listModels(String projectId, String computeRegion, String filter)
    throws IOException {
  // Instantiates a client
  try (AutoMlClient client = AutoMlClient.create()) {

    // A resource that represents Google Cloud Platform location.
    LocationName projectLocation = LocationName.of(projectId, computeRegion);

    // Create list models request.
    ListModelsRequest listModlesRequest =
        ListModelsRequest.newBuilder()
            .setParent(projectLocation.toString())
            .setFilter(filter)
            .build();

    // List all the models available in the region by applying filter.
    System.out.println("List of models:");
    for (Model model : client.listModels(listModlesRequest).iterateAll()) {
      // Display the model information.
      System.out.println(String.format("Model name: %s", model.getName()));
      System.out.println(
          String.format(
              "Model id: %s", model.getName().split("/")[model.getName().split("/").length - 1]));
      System.out.println(String.format("Model display name: %s", model.getDisplayName()));
      System.out.println("Model create time:");
      System.out.println(String.format("\tseconds: %s", model.getCreateTime().getSeconds()));
      System.out.println(String.format("\tnanos: %s", model.getCreateTime().getNanos()));
      System.out.println(String.format("Model deployment state: %s", model.getDeploymentState()));
    }
  }
}

Python

    # TODO(developer): Uncomment and set the following variables
    # project_id = 'PROJECT_ID_HERE'
    # compute_region = 'COMPUTE_REGION_HERE'
    # filter_ = 'DATASET_ID_HERE'

    from google.cloud import automl_v1beta1 as automl

    client = automl.AutoMlClient()

    # A resource that represents Google Cloud Platform location.
    project_location = f"projects/{project_id}/locations/{compute_region}"

    # List all the models available in the region by applying filter.
    request = automl.ListModelsRequest(parent=project_location, filter=filter_)
    response = client.list_models(request=request)

    print("List of models:")
    for model in response:
        # Display the model information.
        if model.deployment_state == automl.Model.DeploymentState.DEPLOYED:
            deployment_state = "deployed"
        else:
            deployment_state = "undeployed"

        print("Model name: {}".format(model.name))
        print("Model id: {}".format(model.name.split("/")[-1]))
        print("Model display name: {}".format(model.display_name))
        print("Model create time: {}".format(model.create_time))
        print("Model deployment state: {}".format(deployment_state))