Model setup recipes
Last updated
Finding objects with Florence-2-base: one 0.23B vision model
The model file is small; what it returns is coordinates and tags, so you need code to read it.
Florence-2 handles several vision tasks through prompts1 rather than fine-tuning. The base model is 0.23B with 463 MB of weights. Changing the tag on the same image yields captions or object boxes, and post-processing turns the output into coordinates.
One model, several tasks
Florence-2 is a sequence-to-sequence model that takes an image and text together. Tags such as <CAPTION>, <OD> and <OCR> make one set of weights caption, detect or read text.
Each task needs a different output length. Detection emits a box for every object, so max_new_tokens needs headroom; a caption is short.

The code and reading the boxes
Bundle the image and tag with AutoProcessor, then pass the generated tokens2 to post_process_generation to get boxes scaled to the image. Skipping that step leaves a raw string with tags.
Each box is an (x, y) pair for top-left and bottom-right. Drawing them once shows immediately whether the values line up.
from PIL import Image
import torch
from transformers import AutoProcessor, AutoModelForCausalLM
name = "microsoft/Florence-2-base"
model = AutoModelForCausalLM.from_pretrained(
name, torch_dtype=torch.float32, trust_remote_code=True)
processor = AutoProcessor.from_pretrained(name, trust_remote_code=True)
image = Image.open("photo.jpg").convert("RGB")
prompt = "<OD>"
inputs = processor(text=prompt, images=image, return_tensors="pt")
with torch.no_grad():
ids = model.generate(input_ids=inputs["input_ids"],
pixel_values=inputs["pixel_values"],
max_new_tokens=1024, num_beams=3)
text = processor.batch_decode(ids, skip_special_tokens=False)[0]
print(processor.post_process_generation(
text, task=prompt, image_size=(image.width, image.height)))Two things to check first
The card requires trust_remote_code=True because the model ships its own Python. Enable it only for repositories you trust, and remember the code is re-fetched when the revision changes.
The base here is pretrained. For immediate detection the fine-tuned -ft variant fits better; base is the starting point. The card's table separates base from base-ft for that reason.

Judging with a single photo
Try three of your own photos per task: do the boxes wrap the objects, does the caption match, does OCR3 keep the digits? That settles fit quickly.
If it does not fit, compare large or -ft on the same photos. Keep the code and tags identical so only the model changes.

Terminology notes
Prompt — The input text sent to a model. For generative models it describes the desired result and strongly shapes the output.
Back to the textToken — A unit into which a model divides input or output for processing.
Back to the textOCR — The process of recognizing characters in images or scanned documents and turning them into text. Table layout and reading order still need the original image to verify.
Back to the text
Frequently asked questions
- What should you check first in this article?
- Florence-2 handles several vision tasks through prompts rather than fine-tuning. The base model is 0.23B with 463 MB of weights. Changing the tag on the same image yields captions or object boxes, and post-processing turns the output into coordinates.
Read next
Model setup recipes
Local CCTV person detection with Frigate: N100, Coral or a Mac?
Image and video generation
Local image generation: software, hardware and your first image
Agents and automation
Adding an Ollama conversation agent to Home Assistant: exposed entities and instructions
read first
What Is a Local AI Agent? When It Makes Sense to Run One
