Skip to content

About

Pure C++20 vision-model inference on brotensor (CPU, CUDA, Metal, Vulkan): SAM, Depth-Anything-V2, DSINE, BiRefNet, OWLv2, DINOv3, StyleGAN3, and ControlNet annotators.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

141 Commits

Folders and files

Repository files navigation

brovisionml

CI CodeQL License: MIT

Vision-model inference in pure C++20. brovisionml runs standalone image-understanding models — promptable segmentation, depth, surface normals, pose, edges, lines, semantic segmentation, background matting, and GAN image generation — on CPU or GPU (CUDA / Metal / Vulkan), loading HuggingFace safetensors checkpoints directly with no conversion or Python runtime.

Each model is a small orchestrator class (load() → optional to(Device::CUDA) → one call per image) plus a matching CLI tool. There is no language model anywhere in the graph: pixels in, masks / maps / boxes / images out. The one text input is OWLv2's detection queries, embedded by its own CLIP text tower and tokenizer.

Models

Model Task API / CLI Docs
SAM promptable segmentation + automatic "segment everything" sam::Sam, sam::AutomaticMaskGenerator / sam_segment, sam_amg docs/sam.md
Depth-Anything-V2 monocular relative depth depth::DepthEstimator / depth_estimate docs/depth-anything.md
DSINE per-pixel surface normals dsine::NormalEstimator / normal_estimate docs/dsine.md
HED soft edges (ControlNet "softedge") hed::SoftEdgeDetector / hed_edges docs/hed.md
Lineart line drawing (ControlNet "lineart") lineart::LineartDetector / lineart docs/lineart.md
MLSD straight line segments (ControlNet "mlsd") mlsd::MLSDdetector / mlsd_lines docs/mlsd.md
OpenPose multi-person body pose (ControlNet "openpose") openpose::OpenposeDetector / openpose_pose docs/openpose.md
SegFormer ADE20K semantic segmentation (ControlNet "seg") segformer::SegformerDetector / segformer_seg docs/segformer.md
BiRefNet background removal / matting birefnet::BiRefNet docs/birefnet.md
OWLv2 open-vocabulary object detection (text queries -> boxes) owlv2::Detector docs/owlv2.md
DINOv3 ViT-H dense-feature backbone dinov3::Backbone docs/dinov3.md
StyleGAN3 image generation (config-R/T) + image→W+ inversion stylegan3::Generator / stylegan3_generate docs/stylegan3.md

Every model is runnable end to end on CPU and CUDA; each doc covers the architecture→op mapping, the API, the GPU/precision path, where the weights come from, and the measured parity against the reference implementation.

Build

# CPU-only
cmake -B build
cmake --build build --config Release
ctest --test-dir build -C Release

# CPU + CUDA (forwards the choice to brotensor's CUDA backend)
cmake -B build -DBROTENSOR_WITH_CUDA=ON
cmake --build build --config Release

# AMD (or any Vulkan GPU): the Vulkan backend
cmake -B build_vk -G Ninja -DCMAKE_BUILD_TYPE=Release -DBROTENSOR_WITH_VULKAN=ON
cmake --build build_vk

CPU is the FP32 default; BROTENSOR_WITH_CUDA=ON / BROTENSOR_WITH_METAL=ON / BROTENSOR_WITH_VULKAN=ON enable a GPU backend (Vulkan is the AMD GPU backend). Other options: BROVISIONML_TESTS / BROVISIONML_TOOLS (default ON standalone), BROVISIONML_INSTALL (default OFF — consume via add_subdirectory).

brovisionml links three sibling libraries: bromath (header-only math), brotensor (tensors + compute kernels + the safetensors loader), and broimage (image decode, resampling, normalize presets). It also links brass to lower its domain GPU kernels from single-source Brass MIR to SPIR-V, PTX, and MSL, while the JavaScript binding in src/api/ links bronze and brass (compiled inside this build tree because the binding has to match the bronze runtime of the program that loads it). A plain clone is all it takes: each dependency is pinned to a commit in CMakeLists.txt (bro_dependency(), cmake/bro_deps.cmake) and resolves the way every repo in the ecosystem resolves one: an existing target wins, then a working tree beside this one at ../<name>, then the pinned commit, fetched at configure. -DFETCHCONTENT_SOURCE_DIR_<NAME>=<path> points one dependency anywhere else. See docs/architecture.md.

Quick start

scripts/download-weights.sh sam-vit-huge       # fetch a checkpoint
sam_segment weights/sam-vit-huge photo.jpg --point 320,240 --out mask.png --device gpu

The same flow in C++:

brovisionml::sam::Sam sam(brovisionml::sam::SamConfig::vit_h());
sam.load("weights/sam-vit-huge");            // dir holding model.safetensors
sam.to(brotensor::Device::CUDA);              // optional; CPU works too
sam.set_image(rgb, w, h, /*channels=*/3);     // slow ViT encode, once
auto seg = sam.segment({{x, y}}, {1}, {});     // cheap per-click decode
// seg.logits[seg.best()*h*w ...] — threshold at 0 for a binary mask

Weights

brovisionml ships code only — no trained weights. Checkpoints with clean HF safetensors releases (SAM, Depth-Anything, SegFormer, DINOv3, BiRefNet) load as-is; scripts/download-weights.sh, download-triposplat.sh, and download-stylegan3.sh fetch them. The annotators that upstream ships only as PyTorch pickles (DSINE, HED, lineart, MLSD, OpenPose) read a one-off, out-of-repo conversion to safetensors. Details: docs/weights.md.

Tests that need real checkpoints look under weights/ and skip cleanly when absent — a fresh clone builds and passes ctest with no downloads.

GPU & performance

Models load on CPU and migrate with .to(Device::CUDA) (or Device::VULKAN / Device::Metal; Device::CUDA aliases to Vulkan when there is no CUDA backend). On CUDA most forwards run FP16 where it's safe — full-FP16 WMMA trunks for the conv annotators, mixed-precision (FP16 GEMMs, FP32 residual streams) for the ViT backbones — engaged automatically by the backend's compute dtype. tools/bench times every family; BROVISIONML_PROFILE=1 prints per-stage timings. The per-model precision table, bench usage, profiler, and the overlapping-tile path for large images are in docs/performance.md.

Every CLI tool takes --device cpu|cuda|metal|vulkan|gpu (default cpu; bench defaults to gpu). gpu is the best backend the build registered (brotensor's default device: CUDA, else Metal, else Vulkan); the older --cuda flag is kept and means --device gpu. An unavailable backend falls back to the CPU with a note on stderr.

Almost all GPU work happens inside brotensor ops; brovisionml's own GPU code is a single pure C++20 Brass MIR module (src/gpu_mir_ops.cpp) for DSINE's two surface-normal domain ops and the DPT (Depth-Anything) bicubic preprocess, lowered on demand to SPIR-V (Vulkan), PTX (CUDA), and MSL (Metal) and dispatched through brotensor::interop — no nvcc, Objective-C++, or glslc toolchain is needed here. See docs/architecture.md.

Platforms. The library builds and its self-contained tests pass on Windows (MSVC), Linux (GCC and Clang) and macOS (arm64); CI covers the CPU build. The CUDA (Windows, Linux), Metal (macOS) and Vulkan (any Vulkan GPU; the AMD path) paths are tested on hardware that has the weights.

Ecosystem

brovisionml is the vision member of the bro ecosystem's inference libraries — brolm (text), brosoundml (audio), brodiffusion (image generation) — but stands alone: its own build, tests, and tools, with no dependency on any of them (brodiffusion builds on brovisionml: its image-to-3D pipeline uses the DINOv3 backbone and BiRefNet). bro links it under BRO_WITH_VISION and exposes it to apps as bro.vision through the JavaScript binding in src/api/ (brovisionml_api). How it relates to the rest of the stack (and why the vision-language encoders live in brolm instead) is covered in docs/architecture.md.

License

MIT

About

Pure C++20 vision-model inference on brotensor (CPU, CUDA, Metal, Vulkan): SAM, Depth-Anything-V2, DSINE, BiRefNet, OWLv2, DINOv3, StyleGAN3, and ControlNet annotators.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages