image-text-to-text Β· vision foundation Β· WebGPU Β· ~460 MB
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.
| Model | onnx-community/Florence-2-base-ft |
|---|---|
| Task | image-text-to-text, task-prompted (caption / detect / OCR / segment) |
| Architecture | DaViT vision encoder + BART-style encoder-decoder (seq2seq) |
| Params / dtype | 230M Β· fp16 (needs shader-f16) |
| Backend | WebGPU (required) |
| Download | ~460 MB, cached after first load |
| License | MIT |
| Web APIs | WebGPU, Web Workers, Canvas, FileReader |
Task β the same model, steered by a token
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.
Run a task to see the prompt.
The raw generated sequence appears here.
The structured result appears here.
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.
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.