MCPcopy Index your code
hub / github.com/JIA-Lab-research/LISA

github.com/JIA-Lab-research/LISA @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
473 symbols 1,633 edges 62 files 110 documented · 23%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Gradio Open in OpenXLab

LISA: Reasoning Segmentation via Large Language Model

LISA: Large Language Instructed Segmentation Assistant

<a href="https://arxiv.org/pdf/2308.00692.pdf"><strong>Paper</strong></a> | 
<a href="https://huggingface.co/xinlai"><strong>Models</strong></a> | 
<a href="#training"><strong>Training</strong></a> | 
<a href="#inference"><strong>Inference</strong></a> | 
<a href="#deployment"><strong>Local Deployment</strong></a> | 
<a href="#dataset"><strong>Dataset</strong></a> | 
<a href=""><strong>Online Demo</strong></a> | 
<a href="https://huggingface.co/collections/Senqiao/lisa-67713837a32d6abf516a162e"><strong>LISA++ Dataset</strong></a> | 
<a href="https://huggingface.co/Senqiao/LISA_Plus_7b"><strong>LISA++ Model</strong></a>

Input Output Input Output
"Who was the president of the US in this image? Please output segmentation mask and explain the reason." "Sure, the segmentation result is [SEG]. The President of the United States in the image is President Obama. "Who was the president of the US in this image? Please output segmentation mask and explain why." "Sure, [SEG]. In the image, the President of the United States is President Trump."
"What can make the woman stand higher? Please output segmentation mask and explain why." "Sure, [SEG]. The woman is standing higher by using a ladder..." "Can you segment the camera lens that is more suitable for photographing nearby objects in this image?" "Sure, [SEG]."
"Can you segment the unusual part in this image and explain why." "Sure, it is [SEG]. In the image, the unusual part is the dog wearing a reindeer antler headband..." "Where to wash hands in this image? Please output segmentation mask." "Sure, [SEG]."
"Can you segment the founder of Alibaba in this image and explain why?" "Sure, it is [SEG]. In the image, the man wearing a red tie and sitting on one of the chairs is Jack Ma, the co-founder of Alibaba Group..." "Please segment Lisa in this figure." "Sure, [SEG]."

News

  • [x] [2024.12.30] We released the LISA++ model and datasets, available here. Our findings show that incorporating Visual COT data can further enhance the model’s global understanding. We will update the paper soon, stay tuned!
  • [x] [2024.6.21] LISA is selected as Oral Presentation in CVPR 2024!
  • [x] [2023.8.30] Release three new models LISA-7B-v1, LISA-7B-v1-explanatory, and LISA-13B-llama2-v1-explanatory. Welcome to check them out!
  • [x] [2023.8.23] Refactor code, and release new model LISA-13B-llama2-v1. Welcome to check it out!
  • [x] [2023.8.9] Training code is released!
  • [x] [2023.8.4] Online Demo is released!
  • [x] [2023.8.4] ReasonSeg Dataset and the LISA-13B-llama2-v0-explanatory model are released!
  • [x] [2023.8.3] Inference code and the LISA-13B-llama2-v0 model are released. Welcome to check them out!
  • [x] [2023.8.2] Paper is released and GitHub repo is created.

LISA: Reasoning Segmentation via Large Language Model [Paper]

Xin Lai, Zhuotao Tian, Yukang Chen, Yanwei Li, Yuhui Yuan, Shu Liu, Jiaya Jia

LISA++: An Improved Baseline for Reasoning Segmentation with Large Language Model [Paper]

Senqiao Yang, Tianyuan Qu, Xin Lai, Zhuotao Tian, Bohao Peng, Shu Liu, Jiaya Jia

Abstract

In this work, we propose a new segmentation task --- reasoning segmentation. The task is designed to output a segmentation mask given a complex and implicit query text. We establish a benchmark comprising over one thousand image-instruction pairs, incorporating intricate reasoning and world knowledge for evaluation purposes. Finally, we present LISA: Large-language Instructed Segmentation Assistant, which inherits the language generation capabilities of the multi-modal Large Language Model (LLM) while also possessing the ability to produce segmentation masks. For more details, please refer to the paper.

Highlights

LISA unlocks the new segmentation capabilities of multi-modal LLMs, and can handle cases involving: 1. complex reasoning; 2. world knowledge; 3. explanatory answers; 4. multi-turn conversation.

LISA also demonstrates robust zero-shot capability when trained exclusively on reasoning-free datasets. In addition, fine-tuning the model with merely 239 reasoning segmentation image-instruction pairs results in further performance enhancement.

Experimental results

Installation

pip install -r requirements.txt
pip install flash-attn --no-build-isolation

Training

Training Data Preparation

The training data consists of 4 types of data:

  1. Semantic segmentation datasets: ADE20K, COCO-Stuff, Mapillary, PACO-LVIS, PASCAL-Part, COCO Images

    Note: For COCO-Stuff, we use the annotation file stuffthingmaps_trainval2017.zip. We only use the PACO-LVIS part in PACO. COCO Images should be put into the dataset/coco/ directory.

  2. Referring segmentation datasets: refCOCO, refCOCO+, refCOCOg, refCLEF (saiapr_tc-12)

    Note: the original links of refCOCO series data are down, and we update them with new ones. If the download speed is super slow or unstable, we also provide a OneDrive link to download. You must also follow the rules that the original datasets require.

  3. Visual Question Answering dataset: LLaVA-Instruct-150k

  4. Reasoning segmentation dataset: ReasonSeg

Download them from the above links, and organize them as follows.

├── dataset
│   ├── ade20k
│   │   ├── annotations
│   │   └── images
│   ├── coco
│   │   └── train2017
│   │       ├── 000000000009.jpg
│   │       └── ...
│   ├── cocostuff
│   │   └── train2017
│   │       ├── 000000000009.png
│   │       └── ...
│   ├── llava_dataset
│   │   └── llava_instruct_150k.json
│   ├── mapillary
│   │   ├── config_v2.0.json
│   │   ├── testing
│   │   ├── training
│   │   └── validation
│   ├── reason_seg
│   │   └── ReasonSeg
│   │       ├── train
│   │       ├── val
│   │       └── explanatory
│   ├── refer_seg
│   │   ├── images
│   │   |   ├── saiapr_tc-12 
│   │   |   └── mscoco
│   │   |       └── images
│   │   |           └── train2014
│   │   ├── refclef
│   │   ├── refcoco
│   │   ├── refcoco+
│   │   └── refcocog
│   └── vlpart
│       ├── paco
│       │   └── annotations
│       └── pascal_part
│           ├── train.json
│           └── VOCdevkit

Pre-trained weights

LLaVA

To train LISA-7B or 13B, you need to follow the instruction to merge the LLaVA delta weights. Typically, we use the final weights LLaVA-Lightning-7B-v1-1 and LLaVA-13B-v1-1 merged from liuhaotian/LLaVA-Lightning-7B-delta-v1-1 and liuhaotian/LLaVA-13b-delta-v1-1, respectively. For Llama2, we can directly use the LLaVA full weights liuhaotian/llava-llama-2-13b-chat-lightning-preview.

SAM ViT-H weights

Download SAM ViT-H pre-trained weights from the link.

Training

deepspeed --master_port=24999 train_ds.py \
  --version="PATH_TO_LLaVA" \
  --dataset_dir='./dataset' \
  --vision_pretrained="PATH_TO_SAM" \
  --dataset="sem_seg||refer_seg||vqa||reason_seg" \
  --sample_rates="9,3,3,1" \
  --exp_name="lisa-7b"

When training is finished, to get the full model weight:

cd ./runs/lisa-7b/ckpt_model && python zero_to_fp32.py . ../pytorch_model.bin

Merge LoRA Weight

Merge the LoRA weights of pytorch_model.bin, save the resulting model into your desired path in the Hugging Face format:

CUDA_VISIBLE_DEVICES="" python merge_lora_weights_and_save_hf_model.py \
  --version="PATH_TO_LLaVA" \
  --weight="PATH_TO_pytorch_model.bin" \
  --save_path="PATH_TO_SAVED_MODEL"

For example:

CUDA_VISIBLE_DEVICES="" python3 merge_lora_weights_and_save_hf_model.py \
  --version="./LLaVA/LLaVA-Lightning-7B-v1-1" \
  --weight="lisa-7b/pytorch_model.bin" \
  --save_path="./LISA-7B"

Validation

deepspeed --master_port=24999 train_ds.py \
  --version="PATH_TO_LISA_HF_Model_Directory" \
  --dataset_dir='./dataset' \
  --vision_pretrained="PATH_TO_SAM" \
  --exp_name="lisa-7b" \
  --eval_only

Note: the v1 model is trained using both train+val sets, so please use the v0 model to reproduce the validation results. (To use the v0 models, please first checkout to the legacy version repo with git checkout 0e26916.)

Inference

To chat with LISA-13B-llama2-v1 or [LISA-13B-llama2-v1-explanatory](https://huggingface.co/xinlai/LISA-13

Core symbols most depended-on inside this repo

from_pretrained
called by 54
model/llava/model/language_model/mpt/adapt_tokenizer.py
get_model
called by 39
model/llava/model/llava_arch.py
cat
called by 35
model/segment_anything/utils/amg.py
items
called by 21
model/segment_anything/utils/amg.py
append_message
called by 19
utils/conversation.py
tokenizer_image_token
called by 19
model/llava/mm_utils.py
update
called by 16
utils/utils.py
copy
called by 14
utils/conversation.py

Shape

Method 255
Function 148
Class 70

Languages

Python100%

Modules by API surface

model/llava/train/train.py31 symbols
model/segment_anything/utils/amg.py26 symbols
model/llava/model/language_model/mpt/modeling_mpt.py26 symbols
utils/grefer.py18 symbols
model/llava/model/language_model/mpt/flash_attn_triton.py17 symbols
model/segment_anything/modeling/image_encoder.py16 symbols
utils/utils.py15 symbols
utils/refer.py15 symbols
model/llava/model/language_model/mpt/hf_prefixlm_converter.py15 symbols
model/llava/model/language_model/mpt/attention.py15 symbols
model/segment_anything/modeling/prompt_encoder.py14 symbols
model/LISA.py13 symbols

For agents

$ claude mcp add LISA \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact