Verify an image's digital watermark

By default, a digital watermark is added to any images generated by an Imagen model version that supports watermark generation. This sample demonstrates how to use the Imagen verification model to determine if an image contains this watermark.

Code sample


Before trying this sample, follow the Python setup instructions in the Vertex AI quickstart using client libraries. For more information, see the Vertex AI Python API reference documentation.

To authenticate to Vertex AI, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

import vertexai
from vertexai.preview.vision_models import (

# TODO(developer): Update and un-comment below lines
# project_id = "PROJECT_ID"
# input_file = "my-input.png"

vertexai.init(project=project_id, location="us-central1")

verification_model = WatermarkVerificationModel.from_pretrained(
image = Image.load_from_file(location=input_file)

watermark_verification_response = verification_model.verify_image(image)

    f"Watermark verification result: {watermark_verification_response.watermark_verification_result}"
# ACCEPT: The image contains a digital watermark.
# REJECT: The image does not contain a digital watermark.

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.