Views
No views yet
1import torch
2from transformers import AutoModelForZeroShotObjectDetection, AutoProcessor
3from transformers.image_utils import load_image
4
5
6# Prepare processor and model
7model_id = "iSEE-Laboratory/llmdet_large"
8device = "cuda" if torch.cuda.is_available() else "cpu"
9processor = AutoProcessor.from_pretrained(model_id)
10model = AutoModelForZeroShotObjectDetection.from_pretrained(model_id).to(device)
11
12# Prepare inputs
13image_url = "http://images.cocodataset.org/val2017/000000039769.jpg"
14image = load_image(image_url)
15text_labels = [["a cat", "a remote control"]]
16inputs = processor(images=image, text=text_labels, return_tensors="pt").to(device)
17
18# Run inference
19with torch.no_grad():
20 outputs = model(**inputs)
21
22# Postprocess outputs
23results = processor.post_process_grounded_object_detection(
24 outputs,
25 threshold=0.4,
26 target_sizes=[(image.height, image.width)]
27)
28
29# Retrieve the first image result
30result = results[0]
31for box, score, labels in zip(result["boxes"], result["scores"], result["labels"]):
32 box = [round(x, 2) for x in box.tolist()]
33 print(f"Detected {labels} with confidence {round(score.item(), 3)} at location {box}")| Model | Pre-Train Data | MiniVal APr | MiniVal APc | MiniVal APf | MiniVal AP | Val1.0 APr | Val1.0 APc | Val1.0 APf | Val1.0 AP |
|---|---|---|---|---|---|---|---|---|---|
| llmdet_tiny | (O365,GoldG,GRIT,V3Det) + GroundingCap-1M | 44.7 | 37.3 | 39.5 | 50.7 | 34.9 | 26.0 | 30.1 | 44.3 |
| llmdet_base | (O365,GoldG,V3Det) + GroundingCap-1M | 48.3 | 40.8 | 43.1 | 54.3 | 38.5 | 28.2 | 34.3 | 47.8 |
| llmdet_large | (O365V2,OpenImageV6,GoldG) + GroundingCap-1M | 51.1 | 45.1 | 46.1 | 56.6 | 42.0 | 31.6 | 38.8 | 50.2 |
1@article{fu2025llmdet,
2 title={LLMDet: Learning Strong Open-Vocabulary Object Detectors under the Supervision of Large Language Models},
3 author={Fu, Shenghao and Yang, Qize and Mo, Qijie and Yan, Junkai and Wei, Xihan and Meng, Jingke and Xie, Xiaohua and Zheng, Wei-Shi},
4 journal={arXiv preprint arXiv:2501.18954},
5 year={2025}
6}