vision
Shared local DINOv2, CLIP, and classical image descriptor library with disk caching.
Offline Python embedding and image-descriptor library powering lookalike and assetfind, providing cached DINOv2 and CLIP embeddings on Apple MPS alongside classical edge, luminance, palette, and saliency metrics.
git clone https://github.com/BestRoiMedia/bestroi-game-tools.gitWhy we built it
Multiple QA and asset tools needed fast, reproducible visual embeddings without paying per-call cloud API fees or duplicating model-loading and caching boilerplate.
Architecture & how it works
vision/embed.py loads facebook/dinov2-small, facebook/dinov2-base, and openai/clip-vit-base-patch32 from the local Hugging Face cache on Apple MPS (or CPU), squashes full frames to preserve whole-room composition, and caches vectors in ~/.cache/vision_embed/ keyed by SHA-256 or pixel hash. It also exposes masked classical descriptors for edge orientation, edge density, Lab histograms, k-means palettes, and spectral-residual saliency.
Key capabilities
- Local DINOv2-small/base CLS + mean-patch embeddings and 16x16 spatial patch grids
- Local CLIP ViT-B/32 text and image embeddings for zero-shot visual search
- Content-addressed disk cache keyed by file SHA-256 or pixel hash
- Weight-masked classical descriptors (edges, luminance, Lab palette transport, saliency)
- Unified image loader supporting PNG, JPG, WEBP, and SVG (via resvg)
Usage example
from vision import embed as V
dino_vecs = V.dino(["./room_a.png", "./room_b.png"], size="base")
img_clip = V.clip_image(["./room_a.png"])
txt_clip = V.clip_text(["moonlit gothic window"])
similarity = img_clip @ txt_clip.T