For the complete documentation index, see llms.txt. This page is also available as Markdown.

PaliGemma 2

Use Google's PaliGemma 2 vision-language model through our Serverless Cloud API

PaliGemma 2 is Google's vision-language model. It accepts an image and a text prompt and returns a text response. We support PaliGemma 2 through our Serverless Cloud API, Dedicated Deployments, and self-hosted Inference.

Code sample

1

Get your API Key

Create a Roboflow account, find your key on the Roboflow API settings page and make it available to your shell:

export ROBOFLOW_API_KEY="your-key-here"
2

Install the dependencies

Install the Inference SDK:

pip install -U inference-sdk supervision
3

Run the model

The sample calls the pretrained paligemma2-3b-pt-224 checkpoint with a caption prompt.

import os
import supervision as sv
from inference_sdk import InferenceHTTPClient

image = sv.load_image_from_url("https://media.roboflow.com/quickstart/dog.jpeg")

client = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key=os.environ["ROBOFLOW_API_KEY"],
)
result = client.infer_lmm(
    image,
    model_id="paligemma2-3b-pt-224",
    prompt="caption en",
    max_new_tokens=64,
)
print(result["response"])

The code above prints the model response to the terminal:

a dog is seen here on the shoulder of a man

Inference speed

Latency measured with Roboflow Inference on 1x NVIDIA L4, batch size 1, generating exactly 128 tokens with greedy decoding from a fixed prompt. Latency scales with output length, so use tokens/sec to estimate other lengths.

Alias
Latency, 128 tokens (ms)
Tokens/sec

paligemma2-3b-pt-224

3986

32

Set api_url to match your deployment target:

  • https://serverless.roboflow.com for the Serverless Cloud API.

  • http://localhost:9001 for a local Inference server.

  • Your Dedicated Deployment URL for a private endpoint.

You can train your own PaliGemma 2 checkpoint on Roboflow and call it by its per-model {workspace}/{model-slug} ID (see Versions, Trainings, and Models). See the Inference documentation for additional prompt formats and supported checkpoints.

PaliGemma 1 (legacy)

The original PaliGemma release is still loadable through the inference package on your own hardware. New projects should use PaliGemma 2 above; this section is kept for existing integrations.

Install the package:

Use inference-gpu[transformers] on a GPU machine.

Visual question answering

Object detection

PaliGemma emits detections as <loc####> tokens rather than JSON, so the response has to be parsed before it can be visualized. Prompt with detect <class>; <class> and decode the tokens into boxes:

Pass the resulting sv.Detections to supervision annotators to draw the boxes.

Last updated

Was this helpful?