← All models

image-text-to-text Β· vision foundation Β· WebGPU Β· ~460 MB

Florence-2 β€” one model, every vision task

Florence-2 is a vision foundation model steered entirely by a task prompt. The same 230M-parameter network captions an image, detects and boxes objects, reads text with OCR, and segments a thing you name β€” you just change the task token. Pick an image, pick a task, and watch it run on your GPU with nothing uploaded.

At a glance

Modelonnx-community/Florence-2-base-ft
Taskimage-text-to-text, task-prompted (caption / detect / OCR / segment)
ArchitectureDaViT vision encoder + BART-style encoder-decoder (seq2seq)
Params / dtype230M Β· fp16 (needs shader-f16)
BackendWebGPU (required)
Download~460 MB, cached after first load
LicenseMIT
Web APIsWebGPU, Web Workers, Canvas, FileReader

Run it

A riverside at golden hour with a swan Two cats on a couch A cozy bedroom
…or drop / choose your own image

Task β€” the same model, steered by a token

The result appears here.

See inside β€” task token in, raw sequence out

Florence-2 doesn't have separate heads for detection, OCR, and captioning β€” every task is the same text-to-text generation, differing only by the token you prepend. Below is the exact prompt the processor built, the raw decoded sequence the model emitted (special location tokens like <loc_512> and all), and the parsed result after post_process_generation turns that sequence into boxes, polygons, or clean text. This is the real output, not a mock-up.

Task token / constructed prompt

Run a task to see the prompt.

Raw model output (before post-processing)

The raw generated sequence appears here.

Parsed result

The structured result appears here.

Why it matters

Florence-2 collapses a whole computer-vision toolbox into one small download. Instead of shipping a captioner, a detector, an OCR engine, and a segmenter β€” each with its own model and server β€” you ship one file and switch tasks with a token, all on-device.

Use cases

Basics

Caption an image β€” the plainest "what is this?" task.

Practical

Detect & count objects with boxes drawn on the image.

Wild

Say a phrase, segment the thing you named β€” grounded masks.

Multi-model

Florence reads an image β†’ Qwen summarizes / answers about it.

How the API works

Florence-2 uses the dedicated vision-seq2seq class. You build the prompt from a task token, run the processor over the image and prompt, generate, decode, then post-process into the shape that task produces:

import { Florence2ForConditionalGeneration, AutoProcessor, load_image }
  from "@huggingface/transformers";

const model = await Florence2ForConditionalGeneration.from_pretrained(
  "onnx-community/Florence-2-base-ft", { dtype: "fp16", device: "webgpu" });   // WebGPU required
const processor = await AutoProcessor.from_pretrained("onnx-community/Florence-2-base-ft");

const image = await load_image(imageURL);
const task = "<OD>";                              // or <CAPTION>, <OCR>, <REFERRING_EXPRESSION_SEGMENTATION>…
const prompts = processor.construct_prompts(task);
const inputs = await processor(image, prompts);

const ids = await model.generate({ ...inputs, max_new_tokens: 512 });
const raw = processor.batch_decode(ids, { skip_special_tokens: false })[0];
const result = processor.post_process_generation(raw, task, image.size);
// result["<OD>"] = { bboxes: [[x1,y1,x2,y2], …], labels: [ … ] }

This page runs exactly that in a Web Worker, and gates on a real WebGPU adapter first β€” with none it shows a labelled needs-WebGPU state instead of a fake result.

References