A simple .NET library for local image captioning with automatic model downloading from HuggingFace. Supports CUDA and CoreML GPU acceleration.
Install
| Product | Versions |
|---|---|
| .NET |
README
LMSupply.Captioner
Local image captioning for .NET with automatic model downloading.
Features
- Zero-config: Models download automatically from HuggingFace
- GPU Acceleration: CUDA, CoreML (macOS)
- Cross-platform: Windows, Linux, macOS
- Simple API: Just 2 lines of code to get started
Quick Start
using LMSupply.Captioner;
// Load the default captioning model
var captioner = await LocalCaptioner.LoadAsync("default");
// Generate a caption
var result = await captioner.CaptionAsync("photo.jpg");
Console.WriteLine(result.Caption);
// Output: "A cat sitting on a windowsill looking outside"
Available Models
| Model ID | Download | Description |
|---|---|---|
default (also fast, auto) |
~1 GB | ViT-GPT2 — fast, one-sentence captions; tends to name a familiar scene rather than the subject |
quality |
~275 MB (int8) · ~545 MB (fp16) · ~1.1 GB (fp32) | Florence-2 base — names the main subjects of everyday photos; brief, detailed or paragraph captions |
quality is published in quantized variants; a load takes the one the hardware tier picks, or the one you name with
QuantizationHint or a qualifier ("quality:fp16"). LocalCaptioner.GetDownloadSizeBytesAsync answers what a load
will download, for a consent screen.
using LMSupply.Captioner;
long bytes = await LocalCaptioner.GetDownloadSizeBytesAsync("quality");
await using var captioner = await LocalCaptioner.LoadAsync("quality",
new CaptionerOptions { Detail = CaptionDetail.Detailed, MaxLength = 100 });
var result = await captioner.CaptionAsync("photo.jpg");
Detail (Brief · Detailed · Paragraph) is read by quality; default captions at one level and refuses any other
value at load. Prompt (caption prefix) is read by default; quality refuses it — its prompt selects the task.
Advanced Usage
using LMSupply; // ExecutionProvider
// Custom options
var options = new CaptionerOptions
{
MaxLength = 50,
Provider = ExecutionProvider.Cuda
};
var captioner = await LocalCaptioner.LoadAsync("default", options);
var result = await captioner.CaptionAsync("image.jpg");
Console.WriteLine($"Caption: {result.Caption}");
Console.WriteLine($"Confidence: {result.Confidence:P1}");
GPU Acceleration
Do not add ONNX Runtime packages (Microsoft.ML.OnnxRuntime*): LMSupply provisions the runtime itself, and a
second copy conflicts with it. ExecutionProvider.Auto uses CUDA when the CUDA 12 runtime and cuDNN 9 are
installed on the machine, CoreML on macOS, and the CPU otherwise. On Windows with an AMD or Intel GPU, ONNX
sessions run on the CPU (DirectML was removed in 0.67.0). See
GPU acceleration.
Changes from Previous Version
Adoption Assessment
Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.
Related Guides & Workflows
Learn how to evaluate, integrate, or audit this package in your .NET project.