Migician: Revealing the Magic of Free-Form Multi-Image Grounding in Multimodal Large Language Models
You Li, Heyu Huang*, Chen Chi, Kaiyu Huang, Chao Huang, Zonghao Guo, Zhiyuan Liu, Jinan Xu, Yuhua Li, Ruixuan Li, Maosong Sun
This repository hosts the usage details of our training dataset MGrounding-630k, benchmark MIG-Bench and the training implementation of Migician, the first competitive Multi-image Grounding MLLM capable of free-form grounding.
- [2025.01.13] ๐ท๐ท๐ท We have further released our massive multi-image grounding training dataset MGrounding_630k and our multi-image grounding benchmark MIG-Bench on Huggingface๐ค. Feel free to download and apply them for your own use.
- [2025.01.12] ๐๐๐ The model weights are now available on HuggingFace! ๐ค Download and have a try at Huggingface Model!
- [2025.01.10] ๐๐๐ We have released our paper on Arxiv at the start of the new year!
The recent advancement of Multimodal Large Language Models (MLLMs) has significantly improved their fine-grained perception of single images and general comprehension across multiple images. However, existing MLLMs still face challenges in achieving precise grounding in complex multi-image scenarios. To address this, we first explore a Chain-of-Thought (CoT) framework that integrates single-image grounding with multi-image comprehension. While partially effective, it remains unstable and struggles to capture abstract visual information due to its non-end-to-end nature. Therefore, we introduce Migician, the first multi-image grounding model capable of performing free-form and accurate grounding across multiple images. To support this, we present the MGrounding-630k dataset, which comprises data for several multi-image grounding tasks derived from existing datasets, along with newly generated free-form grounding instruction-following data. Furthermore, we propose MIG-Bench, a comprehensive benchmark specifically designed for evaluating multi-image grounding capabilities. Experimental results demonstrate that our model achieves significantly superior multi-image grounding capabilities, outperforming the best existing MLLMs by 21.61% and even surpassing much larger 70B models.
Migician surpasses much larger 70B scale model over all tasks on MIG-Bench by a great margin as shown in the radar image above. Additionally, it demonstrates great competitiveness in several general multi-image understanding benchmarks. We are looking forward to the promising applications of Migician on a broad spectrum of real-world scenarios.1. Environment [Back to Top]
Follow the commands below to establish a plausible environment.
conda env create -n migician python=3.10
git clone https://github.com/Michael4933/Migician.git
cd Migician
conda activate migician
pip install -r requirements.txt
2. Data Preparation [Back to Top]
MGrounding-630k encompasses a diverse collection of multi-image grounding tasks and numerous images from different sources. For convenient utilization, we have uploaded the entire training dataset on Huggingface and organized these massive data collections according to their task class.
Note
Due to the nature of multi-image tasks, each training example involves multiple images. As a result, the 600k+ training examples collectively include an even larger number of images.
Please ensure that you have sufficient hard disk storage and a stable internet connection.
You can download the data at ./data/MGrounding-630k
and then simply unzip the corresponding .zip files. This brings you the data structure shown below. We gather all the conversation data at ./data/MGrounding-630k/MGrounding-630k.json
for convenient use, where each training example is labeled with its corresponding sub-task class. The seperate json files for each task is also provided along the way.
The downloading code from huggingface is provided in ./data/download.py
, which realizes one-hit quick download.
The final code structure is show as follows:
Migician/
โโโdata/
โ โโโMGrounding-630k
โ โ โโโ Common_Object
โ โ โ โโโ COCO
โ โ โ โโโ ImageNet
โ โ โ โโโ Object365
โ โ โ โโโ common_train_70k.json ### the addtional .zip files at this level may be of limited help
โ โ โ
โ โ โโโ Difference
โ โ โ โโโ clevr-change
โ โ โ โโโ img-diff
โ โ โ โโโ magicbrush
โ โ โ โโโ spot-the-diff
โ โ โ โโโ diff_train_70k.json
โ โ โ
โ โ โโโ Free-Form
โ โ โ โโโ Object365
โ โ โ โโโ free_form_grounding_130k.json
โ โ โ
โ โ โโโ Group_Grounding
โ โ โ โโโ SA-1B
โ โ โ โโโ _gg_reg_40k.json ### group grounding reg task
โ โ โ โโโ gg_train_120k.json ### group grounding rec task
โ โ โ
โ โ โโโ Object_Tracking
โ โ โ โโโ GOT-10k
โ โ โ โโโ LaSOT
โ โ โ โโโ MOT17_image
โ โ โ โโโ TrackingNet
โ โ โ โโโ ot_train_130k.json
โ โ โ
โ โ โโโ Referring_Grounding
โ โ โ โโโ ImageNet
โ โ โ โโโ refer_train_70k.json
โ โ โ
โ โ โโโ Region_Locating
โ โ โโโ Object365
โ โ โโโ region_train_70k.json
โ โ
โ โโโ MGrounding-630k.json ### containing all conversation data
โ
...
An example structure for training data:
{
"id": "5229016_8929009_6793119_3571391", # you can ignore this
"images": [
"./MGrounding-630k/Group_Grounding/SA-1B/sa_5229016.jpg",
"./MGrounding-630k/Group_Grounding/SA-1B/sa_8929009.jpg",
"./MGrounding-630k/Group_Grounding/SA-1B/sa_6793119.jpg",
"./MGrounding-630k/Group_Grounding/SA-1B/sa_3571391.jpg"
], # they are all organized in the form of a list
"conversations": [
{
"from": "human",
"value": "<image>\n<image>\n<image>\n<image>\nGive the bounding box of the region this sentence refers to: <|object_ref_start|>a statue of a man<|object_ref_end|>." # we adopt special tokens for grounding task
},
{
"from": "gpt",
"value": "It's in the third image. <|box_start|>(316,58),(764,999)<|box_end|>" # 0-1000, relative position, x1 y1 x2 y2 format
},
{
"from": "human",
"value": "Recognize the target region that this sentence refers to: <|object_ref_start|>a woman wearing an orange shirt<|object_ref_end|>."
},
{
"from": "gpt",
"value": "It's in the first image. <|box_start|>(408,656),(578,997)<|box_end|>"
}
],
"type": "gg_train" # group_grounding task
}
3. Inference and Evaluation [Back to Top]
As mentioned in the paper, Migician is finetuned on Qwen2-VL-7B through a progressive two-stage training process with massive amount of data on 8*A100-80G. You can feel the magic๐ช of multi-image grounding through the following code.
from transformers import Qwen2VLForConditionalGeneration, AutoTokenizer, AutoProcessor
from qwen_vl_utils import process_vision_info
import torch
model = Qwen2VLForConditionalGeneration.from_pretrained(
"Your_Migician_Path",
torch_dtype=torch.bfloat16,
attn_implementation="flash_attention_2", # Enabling flash_attention_2 for better acceleration and memory saving is recommended.
device_map="auto",
)
messages = [
{
"role": "user",
"content": [
{
"type": "image", "image": resize("./figs/multi_view_1.png"),
},
{
"type": "image", "image": resize("./figs/multi_view_2.png"),
},
{
"type": "image", "image": resize("./figs/multi_view_3.png"),
},
{
"type": "image", "image": resize("./figs/multi_view_4.png"),
},
{
"type": "text", "text": "Please recognize <|object_ref_start|>the common person appearing in all these images<|object_ref_end|> and locate this person in all these image."
}
]
}
]
text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
image_inputs, video_inputs = process_vision_info(messages)
inputs = processor(text=[text],images=image_inputs,videos=video_inputs,padding=True,return_tensors="pt")
inputs = inputs.to("cuda")
# Inference: Generation of the output
generated_ids = model.generate(**inputs, max_new_tokens=128)
generated_ids_trimmed = [
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
output_text = processor.batch_decode(
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
)
print(output_text)
๐ค๐MIG-Bench enables the comprehensive evaluation of current MLLM's MIG ability. Your can directly download it from hugggingface and implement your own evaluation. The file structure for evaluation is as follows:
Migician/
โโโeval/
โ โโโ MIG-Bench
โ โ โโโ images
โ โ โ โโโ common # 10 diverse tasks
โ โ โ โโโ correspondence
โ โ โ โโโ group_grounding
โ โ โ ...
โ โ โโโ MIG_data.json # could be directly used for evaluation
โ โ
โ โโโ eval_output/
โ โโโ others/ # MMIU and MIBench
โ โ
โ โโโ MIG_bench_cot.py # Executing MIG through single-image CoT framework
โ โโโ MIG_bench_eval.py # Executing MIG by direct inference
โ โโโ utils.py
โ โโโ requirements.txt
โ โโโ chat.py
Each testing example is formatted as below, which includes the key informantion such as task class label, image paths, question and ground truth.
Note
The groundtruth coordinates are normalized as float within 0-1, following the x1 y1 x2 y2
format.
The numerical numbers are relative positions regarding the width and height of the whole image.
{
"task": "reasoning",
"images": [
"./MIG-Bench/images/reasoning/case097_1.png",
"./MIG-Bench/images/reasoning/case097_2.png"
],
"question": "Which item in Image-2 share the similar feature of Image-1? Find it and locate it in the second image. ",
"answer": [
0.418,
0.391,
0.595,
0.546
],
"additional_info": "Which item in Image-2 share the similar feature of Image-1?",
"need_format": true
}
You can conduct one-hit evaluation for SEVEN different models[Migician, Qwen2-VL, InternVL2, MiniCPM-V_2.6, LLaVA-OneVision, mPLUG-Owl3, and Mantis] on MIG-Bench. Simply run the MIG_bench_eval.py script and it will report [email protected], [email protected], [email protected] and ave-iou scores. We further facilitate the evaluation for ๐คMIBench and ๐คMMIU in MIG_bench_eval.py for different models.
4. Finetune [Back to Top]
Our two-stage training process is conducted mainly based on ๐ญ๐ญ๐ญLlamafactory, where the whole LLM backbone parameters are finetuned. We provide our training script for these two stages and the requirements.txt file.
Migician/
โโโ train/
โ โโโ stage-1_finetune_full.yaml
โ โโโ stage-2_finetune_full.yaml
โ โโโ requirements.txt
@article{li2025migician,
title={Migician: Revealing the Magic of Free-Form Multi-Image Grounding in Multimodal Large Language Models},
author={Li, You and Huang, Heyu and Chen, Chi and Huang, Kaiyu and Huang, Chao and Guo, Zonghao and Liu, Zhiyuan and Xu, Jinan and Li, Yuhua and Li, Ruixuan and others},
journal={arXiv preprint arXiv:2501.05767},
year={2025}
}