Contextual Object Detection with Multimodal Large Language Models

Yuhang Zang, Wei Li, Jun Han, Kaiyang Zhou, Chen Change Loy

TL;DR

ContextDET is a new multimodal framework that gives Large Language Models (LLMs) "eyes" to not just describe, but precisely locate objects in an image. By using a "generate-then-detect" approach, it can identify and draw bounding boxes for over 10,000 unique object types based on the specific context of a conversation or a caption.

What Problem Does This Paper Address?

While Multimodal Large Language Models (MLLMs) like GPT-4 or LLaVA are excellent at describing scenes or answering questions, they generally lack the "perception" ability of traditional object detectors. They can tell you there is a "hockey goalie" in a photo, but they can't point to exactly where that goalie is.

Conversely, traditional object detectors are often stuck with a "closed vocabulary"—they are trained to find a fixed list of categories (like the 80 classes in the COCO dataset). In the real world, a "person" isn't just a person; depending on the context, they are a "groom," a "worker," or a "cowboy." The authors introduce Contextual Object Detection to bridge this gap, requiring models to locate objects based on nuanced, human-AI interactive contexts.

Methods

The authors propose ContextDET, which flips the traditional "locate-then-classify" detection pipeline on its head with a generate-then-detect framework.

Fig. 2: Our ContextDET is a unified end-to-end framework, being capable of taking different language token inputs for

The architecture consists of three main components:

  1. Visual Encoder: Extracts image features. It produces "local tokens" to help the LLM understand the scene and "full tokens" to help the decoder find precise boundaries.
  2. Pre-trained LLM: Acts as the "brain." It takes the visual tokens and a text prompt (like a question or a partial caption) to generate text.
  3. Visual Decoder: This is the novel part. It takes the latent embeddings of the specific words the LLM just generated (e.g., "bride" or "labrador") and uses them as conditional queries. It then searches the image features to find the bounding box that best matches that specific word.

This allows the model to detect anything it can name, effectively opening the detection vocabulary to the entirety of the LLM's training.

Datasets

To train and test this new capability, the authors created the CODE (Contextual Object DEtection) benchmark.

  • Source: Built upon Flickr30k and Flickr30k Entities.
  • Scale: Includes 10,346 unique object names—a massive jump from the 80 classes in COCO or the ~1,200 in LVIS.
  • Tasks: The benchmark evaluates three scenarios:
  • Cloze Test: Fill in a masked word in a caption and locate it.
  • Visual Captioning: Generate a caption and locate all mentioned objects.
  • Question Answering: Answer a question and locate the subject of the answer.

The model was also evaluated on standard open-vocabulary detection (OV-COCO) and referring image segmentation tasks.

Key Insights and Ideas

  • Context is King: A generic "dog" category is insufficient when a user asks about a "labrador." ContextDET uses the LLM's internal state to differentiate these nuances.
  • Embeddings as Priors: The paper shows that the hidden layers of an LLM contain rich information that can be directly "repurposed" to guide a visual decoder.
  • End-to-End vs. Cascade: Many current systems "cascade" models (e.g., use LLaVA to get text, then use a separate model like GLIP to find boxes). ContextDET performs better because it is trained end-to-end; the detection is physically tied to the LLM's word generation.
  • Local Visual Tokens Matter: The authors found that providing the LLM with localized image patches (rather than just a global summary) was critical for it to generate the correct words to be detected.

Key Results

ContextDET demonstrated significant improvements over "cascade" baselines (combinations of BLIP-2/LLaVA and GLIP):

  • CODE Benchmark: Outperformed all baselines across Cloze, QA, and Captioning tasks.
  • Open-Vocabulary Detection: On the OV-COCO benchmark, it achieved 36.8 AP on novel classes, setting a new state-of-the-art and beating the previous best (BARON) by 2.8%.
  • Vocabulary Breadth: Qualitatively, the model successfully detected "long-tail" and open-world concepts like "Harry Potter," "Pikachu," and "Lionel Messi" that are not present in standard detection datasets.
Fig. 1: We present a new contextual object detection task include (a) look at the image and complete the masked object names and locations; (b) predict the caption and the boxes of objects existing in the caption; (c) answer a question about the names and locations of objects. Unlike the traditional object detection task that typically focuses on detecting a limited set of pre-defined object classes such as ‘person’, our task requires predicting more specific names (e.g., ‘hockey goalie’, ‘groom’, or ‘bride’) based on contextual understanding.

Limitations and Future Work

  • Annotation Cost: Training requires data where words in captions are explicitly linked to bounding boxes, which is expensive to produce at scale.
  • Robustness: The model is less robust when dealing with heavily occluded objects or very rare terms (like "earth" seen from space).
  • Interactive Refinement: The authors suggest future work could involve "instruction tuning" for detection—allowing a user to say "move that box slightly to the left" or "that's not an eagle, it's a falcon," and having the model update its visual perception accordingly.

Summary updated

Abstract

Recent Multimodal Large Language Models (MLLMs) are remarkable in vision-language tasks, such as image captioning and question answering, but lack the essential perception ability, i.e., object detection. In this work, we address this limitation by introducing a novel research problem of contextual object detection -- understanding visible objects within different human-AI interactive contexts. Three representative scenarios are investigated, including the language cloze test, visual captioning, and question answering. Moreover, we present ContextDET, a unified multimodal model that is capable of end-to-end differentiable modeling of visual-language contexts, so as to locate, identify, and associate visual objects with language inputs for human-AI interaction. Our ContextDET involves three key submodels: (i) a visual encoder for extracting visual representations, (ii) a pre-trained LLM for multimodal context decoding, and (iii) a visual decoder for predicting bounding boxes given contextual object words. The new generate-then-detect framework enables us to detect object words within human vocabulary. Extensive experiments show the advantages of ContextDET on our proposed CODE benchmark, open-vocabulary detection, and referring image segmentation. Github: https://github.com/yuhangzang/ContextDET.
BibTeX
@article{zang2025contextual,
  author = {Yuhang Zang and Wei Li and Jun Han and Kaiyang Zhou and Chen Change Loy},
  title = {{Contextual Object Detection with Multimodal Large Language Models}},
  journal = {Int. J. Comput. Vis.},
  year = {2025},
  doi = {10.1007/s11263-024-02214-4},
}
Figure