Views
No views yet



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[!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.
./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. We just want the best for ya~~~🥰./data/download.py, which realizes one-hit quick download.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
│
...{
"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
}
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)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[!NOTE] The groundtruth coordinates are normalized as float within 0-1, following thex1 y1 x2 y2format.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
}Migician/
├── train/
│ ├── stage-1_finetune_full.yaml
│ ├── stage-2_finetune_full.yaml
│ ├── requirements.txt1@misc{li2025migicianrevealingmagicfreeform,
2 title={Migician: Revealing the Magic of Free-Form Multi-Image Grounding in Multimodal Large Language Models},
3 author={You Li and Heyu Huang and Chen Chi and Kaiyu Huang and Chao Huang and Zonghao Guo and Zhiyuan Liu and Jinan Xu and Yuhua Li and Ruixuan Li and Maosong Sun},
4 year={2025},
5 url={https://arxiv.org/abs/2501.05767},
6}