Skip to main content
net8.0net9.0net10.0

Implementing the Florence-2-base model for image understanding. Supports captioning, OCR, and object detection with optional phrase grounding. Uses ONNX models from huggingface.co/onnx-community/Florence-2-base. Enables various output tasks including detailed captioning, region-based OCR, and flexible object detection.

Published
Dec 7, 2025
10mo ago
Total Downloads
21.3K
21,292

Install

dotnet add package Florence2 --version 25.12.63047
ProductVersions
.NET
net10.0net8.0net9.0

README

Florence2 — C# Wrapper for Microsoft’s Florence-2 Vision Model

A lightweight, easy-to-use C# library that provides access to Microsoft’s Florence-2-base models for advanced image understanding tasks — including captioning, OCR, object detection, and phrase grounding.

This project gives .NET developers a clean API to run Florence-2 locally without needing Python or the original reference implementation.

📦 NuGet: https://www.nuget.org/packages/Florence2


✨ Features

  • Image Captioning Generate concise or richly detailed descriptions of images.

  • Optical Character Recognition (OCR) Extract text from entire images or specific regions.

  • Region-based OCR Provide bounding boxes and retrieve text only from selected areas.

  • Object Detection Detect and label objects with bounding boxes.

  • Phrase Grounding (optional) Highlight image regions relevant to a given phrase or textual query.

  • Local Model Execution Automatically downloads and loads the Florence-2-base ONNX models.


🚀 Quick Start

1. Install the package

dotnet add package Florence2

Or get it on NuGet: https://www.nuget.org/packages/Florence2


2. Example Usage

using Florence2;

// Download models if needed
var modelSource = new FlorenceModelDownloader("./models");
await modelSource.DownloadModelsAsync();

// Create model instance
var model = new Florence2Model(modelSource);

// Load an image stream
using var imgStream = File.OpenRead("example.jpg");

// Optional text for phrase grounding (may be null)
string phrase = "the red car";

// Choose a task: Captioning / OCR / ObjectDetection / PhraseGrounding / RegionOCR
var task = FlorenceTask.Caption;

// Run inference
var results = model.Run(task, imgStream, textInput: phrase);

// View results
Console.WriteLine(JsonSerializer.Serialize(results, new JsonSerializerOptions() { WriteIndented = true }));

📚 Supported Tasks

Task Description
Caption Generates a caption describing the entire image.
OCR Extracts all text from the image.
RegionOCR Extracts text from specified bounding boxes.
ObjectDetection Detects objects and provides bounding boxes + labels.
PhraseGrounding Highlights regions relating to a provided phrase.

📦 Model Files

Models are downloaded automatically via FlorenceModelDownloader, but you can also supply your own model directory. The library expects Florence-2-base ONNX models compatible with Microsoft’s open-source release.


🤝 Contributing

Contributions, issues, and pull requests are welcome! If you find a bug or have a feature request, feel free to open an issue.


đź“„ License

MIT — see the LICENSE file for details.

Changes from Previous Version

v25.7.59767v25.12.63047
Added Frameworks
net9.0net10.0

Adoption Assessment

Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.

Compatibility metadata lists 3 target frameworks; confirm the exact target used by your application.The published metadata declares 15 direct dependency entries across framework groups. Inspect the resolved dependency graph for your target framework.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.