Modellbereitstellung rückgängig machen

Nach einer Bereitstellung und nachdem Vorhersagen gemacht wurden, können Sie die Bereitstellung des Modells manuell rückgängig zu machen, damit keine weiteren Kosten anfallen.

Bereitstellung von Codebeispielen rückgängig machen

Web-UI

  1. Öffnen Sie Vision Dashboard und wählen Sie in der linken Navigationsleiste den Tab Modelle mit dem Glühbirnensymbol aus, um die verfügbaren Modelle anzuzeigen.

    Wenn Sie die Modelle für ein anderes Projekt ansehen möchten, wählen Sie das Projekt in der Drop-down-Liste rechts oben in der Titelleiste aus.

  2. Klicken Sie auf die Zeile für das Modell, das Sie verwenden möchten, um die Bilder mit Labels zu versehen.
  3. Wählen Sie den Tab Test und Nutzung direkt unter der Titelleiste aus.
  4. Wählen Sie aus dem Banner unterhalb des Modellnamens Deployment entfernen aus, um das Fenster zum Aufheben der Bereitstellung zu öffnen.

    Grafik: Pop-up-Menü "Deployment entfernen"
  5. Wählen Sie Remove deployment (Deployment entfernen) aus, um die Bereitstellung des Modells zu entfernen.

    Modell wird bereitgestellt Modell wird bereitgestellt
  6. Sie erhalten eine E-Mail, wenn die Bereitstellung vollständig entfernt wurde.

REST

Ersetzen Sie dabei folgende Werte für die Anfragedaten:

  • project-id: die ID Ihres GCP-Projekts.
  • model-id: die ID Ihres Modells aus der Antwort beim Erstellen des Modells. Sie ist das letzte Element des Modellnamens. Beispiel:
    • Modellname: projects/project-id/locations/location-id/models/IOD4412217016962778756
    • Modell-ID: IOD4412217016962778756

HTTP-Methode und URL:

POST https://automl.googleapis.com/v1/projects/PROJECT_ID/locations/us-
central1/models/MODEL_ID:undeploy

Senden Sie die Anfrage mithilfe einer der folgenden Optionen:

curl

Führen Sie folgenden Befehl aus:

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: project-id" \
-H "Content-Type: application/json; charset=utf-8" \
-d "" \
"https://automl.googleapis.com/v1/projects/PROJECT_ID/locations/us- central1/models/MODEL_ID:undeploy"

PowerShell

Führen Sie folgenden Befehl aus:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "project-id" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-Uri "https://automl.googleapis.com/v1/projects/PROJECT_ID/locations/us- central1/models/MODEL_ID:undeploy" | Select-Object -Expand Content
Sie sollten eine Antwort mit der ID des Bereitstellungsvorgangs erhalten:
{
  "name": "projects/PROJECT_ID/locations/us-central1/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.automl.v1.OperationMetadata",
    "createTime": "2019-08-07T22:19:50.828033Z",
    "updateTime": "2019-08-07T22:19:50.828033Z",
    "undeployModelDetails": {}
  }
}

Sie können den Status eines Vorgangs mit der folgenden HTTP-Methode und URL abrufen:

GET https://automl.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/operations/OPERATION_ID

Der Status eines abgeschlossenen Vorgangs sieht ungefähr so aus:

{
  "name": "projects/PROJECT_ID/locations/us-central1/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.automl.v1.OperationMetadata",
    "createTime": "2019-06-21T16:47:21.704674Z",
    "updateTime": "2019-06-21T17:01:00.802505Z",
    "deployModelDetails": {}
  },
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.protobuf.Empty"
  }
}

Go

Bevor Sie dieses Beispiel ausprobieren, folgen Sie der Einrichtungsanleitung für diese Sprache auf der Seite Clientbibliotheken.

import (
	"context"
	"fmt"
	"io"

	automl "cloud.google.com/go/automl/apiv1"
	"cloud.google.com/go/automl/apiv1/automlpb"
)

// undeployModel deploys a model.
func undeployModel(w io.Writer, projectID string, location string, modelID string) error {
	// projectID := "my-project-id"
	// location := "us-central1"
	// modelID := "TRL123456789..."

	ctx := context.Background()
	client, err := automl.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("NewClient: %w", err)
	}
	defer client.Close()

	req := &automlpb.UndeployModelRequest{
		Name: fmt.Sprintf("projects/%s/locations/%s/models/%s", projectID, location, modelID),
	}

	op, err := client.UndeployModel(ctx, req)
	if err != nil {
		return fmt.Errorf("DeployModel: %w", err)
	}
	fmt.Fprintf(w, "Processing operation name: %q\n", op.Name())

	if err := op.Wait(ctx); err != nil {
		return fmt.Errorf("Wait: %w", err)
	}

	fmt.Fprintf(w, "Model undeployed.\n")

	return nil
}

Java

Bevor Sie dieses Beispiel ausprobieren, folgen Sie der Einrichtungsanleitung für diese Sprache auf der Seite Clientbibliotheken.

import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.automl.v1.AutoMlClient;
import com.google.cloud.automl.v1.ModelName;
import com.google.cloud.automl.v1.OperationMetadata;
import com.google.cloud.automl.v1.UndeployModelRequest;
import com.google.protobuf.Empty;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

class UndeployModel {

  static void undeployModel() throws IOException, ExecutionException, InterruptedException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "YOUR_PROJECT_ID";
    String modelId = "YOUR_MODEL_ID";
    undeployModel(projectId, modelId);
  }

  // Undeploy a model from prediction
  static void undeployModel(String projectId, String modelId)
      throws IOException, ExecutionException, InterruptedException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create()) {
      // Get the full path of the model.
      ModelName modelFullId = ModelName.of(projectId, "us-central1", modelId);
      UndeployModelRequest request =
          UndeployModelRequest.newBuilder().setName(modelFullId.toString()).build();
      OperationFuture<Empty, OperationMetadata> future = client.undeployModelAsync(request);

      future.get();
      System.out.println("Model undeployment finished");
    }
  }
}

Node.js

Bevor Sie dieses Beispiel ausprobieren, folgen Sie der Einrichtungsanleitung für diese Sprache auf der Seite Clientbibliotheken.

/**
 * TODO(developer): Uncomment these variables before running the sample.
 */
// const projectId = 'YOUR_PROJECT_ID';
// const location = 'us-central1';
// const modelId = 'YOUR_MODEL_ID';

// Imports the Google Cloud AutoML library
const {AutoMlClient} = require('@google-cloud/automl').v1;

// Instantiates a client
const client = new AutoMlClient();

async function undeployModel() {
  // Construct request
  const request = {
    name: client.modelPath(projectId, location, modelId),
  };

  const [operation] = await client.undeployModel(request);

  // Wait for operation to complete.
  const [response] = await operation.promise();
  console.log(`Model undeployment finished. ${response}`);
}

undeployModel();

Python

Bevor Sie dieses Beispiel ausprobieren, folgen Sie der Einrichtungsanleitung für diese Sprache auf der Seite Clientbibliotheken.

from google.cloud import automl

# TODO(developer): Uncomment and set the following variables
# project_id = "YOUR_PROJECT_ID"
# model_id = "YOUR_MODEL_ID"

client = automl.AutoMlClient()
# Get the full path of the model.
model_full_id = client.model_path(project_id, "us-central1", model_id)
response = client.undeploy_model(name=model_full_id)

print(f"Model undeployment finished. {response.result()}")

Weitere Sprachen

C#: Folgen Sie der Anleitung zur Einrichtung von C# auf der Seite der Clientbibliotheken und rufen Sie dann die AutoML Vision-Referenzdokumentation für .NET auf.

PHP: Folgen Sie der Anleitung zur Einrichtung von PHP auf der Seite der Clientbibliotheken und rufen Sie dann die AutoML Vision-Referenzdokumentation für PHP auf.

Ruby: Folgen Sie der Anleitung zur Einrichtung von Ruby auf der Seite der Clientbibliotheken und rufen Sie dann die AutoML Vision-Referenzdokumentation für Ruby auf.