VLM-EDETR + NIG (OV-LVIS, CLIP RN50)
Open-vocabulary object detector with two kinds of uncertainty:
- classification: an evidential Beta head per (query, class) gives the score and the
uncertainty
u = 2 / S(VLM-EDETR); - localization: a Normal-Inverse-Gamma (NIG) head gives a Student-t distribution for the error of each box coordinate (cx, cy, w, h, in image-normalized units).
Code: github.com/thisistejaspandey/e-detr
Demo
Opens notebook.ipynb in Colab (also under "Use this model → Google Colab"):
type any prompts on your own images and see each detection's score, Beta uncertainty and NIG box
uncertainty (a heatmap of boxes sampled from the predicted distribution). Run all cells; setup
takes 1–2 minutes.
Files
| file | use |
|---|---|
vlm_nig_edetr_lvis.safetensors | state dict (the demo loads this) |
vlm_nig_edetr_lvis.pth | same weights as {"model": state_dict}, for the edetr tools (load_vlm_checkpoint, pixi run infer) |
notebook.ipynb, gradio_demo.py | the Colab demo |
elephant.jpg | example photo: "The Elephant in the election turned out to be a Hung Parliament" by Gavin Anderson, CC BY-SA 2.0 |
The decoder layers share one NIG head, stored once as nig_embed.0. The checkpoint carries the
1203 LVIS class text embeddings (text_embeddings); set model.text_embeddings to your own
prompts' CLIP embeddings to detect anything else.
Usage
import torch
from PIL import Image
from safetensors.torch import load_file
from edetr.data.lvis import clip_transforms
from edetr.vlm.model import VLMNIGEdetr, build_text_embeddings
from edetr.vlm.postprocess import VLMPostProcessor
model = VLMNIGEdetr(num_classes=1203, multi_scale=None)
model.load_state_dict(load_file("vlm_nig_edetr_lvis.safetensors"), strict=False) # shared NIG head
model.eval()
prompts = ["elephant", "car"]
model.text_embeddings = build_text_embeddings(prompts, "RN50")
image = Image.open("image.jpg").convert("RGB")
with torch.no_grad():
out = model(clip_transforms(train=False)(image).unsqueeze(0))
w, h = image.size
det = VLMPostProcessor(len(prompts), 100, score_type="uncertainty_weighted")(
out, image_ids=[0], image_sizes=torch.tensor([[h, w]])
)[0]
det.boxes, det.scores, det.labels # boxes are normalized cx, cy, w, h
Box uncertainty
The NIG head predicts (ν, α, β) for each query and box coordinate. Its loss is the NIG negative
log-likelihood, so the error target − box of each coordinate is a Student-t with
df = 2α and scale s = √(β(1 + ν) / (να)):
from scipy import stats
nig = out["pred_nig"] # [1, queries, 4] per parameter
df = 2 * nig.alpha
scale = (nig.beta * (1 + nig.v) / (nig.v * nig.alpha)).sqrt() # normalized units
half_width_90 = torch.from_numpy(stats.t.ppf(0.95, df.numpy())) * scale # 90% interval
boxes = out["pred_boxes"].sigmoid() # the matching per-query boxes
License
Apache 2.0. The checkpoint includes the frozen CLIP RN50 image-encoder weights from
OpenAI CLIP (MIT License, Copyright (c) 2021 OpenAI); the CLIP
text encoder is downloaded separately by the clip package.