• Stars
    star
    1,680
  • Rank 27,795 (Top 0.6 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 1 year ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Project Page for "LISA: Reasoning Segmentation via Large Language Model"

Gradio Open in OpenXLab

LISA: Reasoning Segmentation via Large Language Model

LISA: Large Language Instructed Segmentation Assistant

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

LISA: Reasoning Segmentation via Large Language Model [Paper]
Xin Lai, Zhuotao Tian, Yukang Chen, Yanwei Li, Yuhui Yuan, 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_LLaVA" \
  --dataset_dir='./dataset' \
  --vision_pretrained="PATH_TO_SAM" \
  --exp_name="lisa-7b" \
  --weight='PATH_TO_pytorch_model.bin' \
  --eval_only

Inference

To chat with LISA-13B-llama2-v1 or LISA-13B-llama2-v1-explanatory: (Note that chat.py currently does not support v0 models (i.e., LISA-13B-llama2-v0 and LISA-13B-llama2-v0-explanatory), if you want to use the v0 models, please first checkout to the legacy version repo git checkout 0e26916.)

CUDA_VISIBLE_DEVICES=0 python chat.py --version='xinlai/LISA-13B-llama2-v1'
CUDA_VISIBLE_DEVICES=0 python chat.py --version='xinlai/LISA-13B-llama2-v1-explanatory'

To use bf16 or fp16 data type for inference:

CUDA_VISIBLE_DEVICES=0 python chat.py --version='xinlai/LISA-13B-llama2-v1' --precision='bf16'

To use 8bit or 4bit data type for inference (this enables running 13B model on a single 24G or 12G GPU at some cost of generation quality):

CUDA_VISIBLE_DEVICES=0 python chat.py --version='xinlai/LISA-13B-llama2-v1' --precision='fp16' --load_in_8bit
CUDA_VISIBLE_DEVICES=0 python chat.py --version='xinlai/LISA-13B-llama2-v1' --precision='fp16' --load_in_4bit

Hint: for 13B model, 16-bit inference consumes 30G VRAM with a single GPU, 8-bit inference consumes 16G, and 4-bit inference consumes 9G.

After that, input the text prompt and then the image path. For example,

- Please input your prompt: Where can the driver see the car speed in this image? Please output segmentation mask.
- Please input the image path: imgs/example1.jpg

- Please input your prompt: Can you segment the food that tastes spicy and hot?
- Please input the image path: imgs/example2.jpg

The results should be like:

Deployment

CUDA_VISIBLE_DEVICES=0 python app.py --version='xinlai/LISA-13B-llama2-v1 --load_in_4bit'
CUDA_VISIBLE_DEVICES=0 python app.py --version='xinlai/LISA-13B-llama2-v1-explanatory --load_in_4bit'

By default, we use 4-bit quantization. Feel free to delete the --load_in_4bit argument for 16-bit inference or replace it with --load_in_8bit argument for 8-bit inference.

Dataset

In ReasonSeg, we have collected 1218 images (239 train, 200 val, and 779 test). The training and validation sets can be download from this link.

Each image is provided with an annotation JSON file:

image_1.jpg, image_1.json
image_2.jpg, image_2.json
...
image_n.jpg, image_n.json

Important keys contained in JSON files:

- "text": text instructions.
- "is_sentence": whether the text instructions are long sentences.
- "shapes": target polygons.

The elements of the "shapes" exhibit two categories, namely "target" and "ignore". The former category is indispensable for evaluation, while the latter category denotes the ambiguous region and hence disregarded during the evaluation process.

We provide a script that demonstrates how to process the annotations:

python3 utils/data_processing.py

Besides, we leveraged GPT-3.5 for rephrasing instructions, so images in the training set may have more than one instructions (but fewer than six) in the "text" field. During training, users may randomly select one as the text query to obtain a better model.

Citation

If you find this project useful in your research, please consider citing:

@article{lai2023lisa,
  title={LISA: Reasoning Segmentation via Large Language Model},
  author={Lai, Xin and Tian, Zhuotao and Chen, Yukang and Li, Yanwei and Yuan, Yuhui and Liu, Shu and Jia, Jiaya},
  journal={arXiv preprint arXiv:2308.00692},
  year={2023}
}

Acknowledgement

  • This work is built upon the LLaVA and SAM.

More Repositories

1

MGM

Official repo for "Mini-Gemini: Mining the Potential of Multi-modality Vision Language Models"
Python
3,111
star
2

LongLoRA

Code and documents of LongLoRA and LongAlpaca (ICLR 2024 Oral)
Python
2,563
star
3

VoxelNeXt

VoxelNeXt: Fully Sparse VoxelNet for 3D Object Detection and Tracking (CVPR 2023)
Python
692
star
4

LLaMA-VID

LLaMA-VID: An Image is Worth 2 Tokens in Large Language Models (ECCV 2024)
Python
656
star
5

DeepUPE

Underexposed Photo Enhancement Using Deep Illumination Estimation
Python
566
star
6

3D-Box-Segment-Anything

We extend Segment Anything to 3D perception by combining it with VoxelNeXt.
Jupyter Notebook
524
star
7

LLMGA

This project is the official implementation of 'LLMGA: Multimodal Large Language Model based Generation Assistant', ECCV2024
Python
424
star
8

ControlNeXt

Controllable video and image Generation, SVD, Animate Anyone, ControlNet, LoRA
Python
417
star
9

PanopticFCN

Fully Convolutional Networks for Panoptic Segmentation (CVPR2021 Oral)
Python
391
star
10

PointGroup

PointGroup: Dual-Set Point Grouping for 3D Instance Segmentation
Python
376
star
11

3DSSD

3DSSD: Point-based 3D Single Stage Object Detector (CVPR 2020)
Python
375
star
12

Video-P2P

Video-P2P: Video Editing with Cross-attention Control
Python
365
star
13

FocalsConv

Focal Sparse Convolutional Networks for 3D Object Detection (CVPR 2022, Oral)
Python
364
star
14

Stratified-Transformer

Stratified Transformer for 3D Point Cloud Segmentation (CVPR 2022)
Python
362
star
15

DSGN

DSGN: Deep Stereo Geometry Network for 3D Object Detection (CVPR 2020)
Python
324
star
16

PFENet

PFENet: Prior Guided Feature Enrichment Network for Few-shot Segmentation (TPAMI).
Python
307
star
17

SphereFormer

The official implementation for "Spherical Transformer for LiDAR-based 3D Recognition" (CVPR 2023).
Python
300
star
18

GridMask

Python
281
star
19

ReviewKD

Distilling Knowledge via Knowledge Review, CVPR 2021
Python
249
star
20

Parametric-Contrastive-Learning

Parametric Contrastive Learning (ICCV2021) & GPaCo (TPAMI 2023)
Python
237
star
21

Step-DPO

Implementation for "Step-DPO: Step-wise Preference Optimization for Long-chain Reasoning of LLMs"
Python
232
star
22

Simple-SR

Include MuCAN, LAPAR, etc.
Python
224
star
23

UVTR

Unifying Voxel-based Representation with Transformer for 3D Object Detection (NeurIPS 2022)
Python
224
star
24

Facelet_Bank

Facelet-Bank for Fast Portrait Manipulation (pytorch)
Python
208
star
25

SA-AutoAug

Scale-aware Automatic Augmentation for Object Detection (CVPR 2021)
Python
196
star
26

LargeKernel3D

LargeKernel3D: Scaling up Kernels in 3D Sparse CNNs (CVPR 2023)
Python
189
star
27

SNR-Aware-Low-Light-Enhance

This is the official implementation for the paper "SNR-aware low-light image enhancement" in CVPR2022
Python
160
star
28

MASA-SR

MASA-SR: Matching Acceleration and Spatial Adaptation for Reference-Based Image Super-Resolution (CVPR2021)
Python
158
star
29

ECCV22-P3AFormer-Tracking-Objects-as-Pixel-wise-Distributions

The official code for our ECCV22 oral paper: tracking objects as pixel-wise distributions.
Python
158
star
30

Context-Aware-Consistency

Semi-supervised Semantic Segmentation with Directional Context-aware Consistency (CVPR 2021)
Python
155
star
31

SparseTransformer

A fast and memory-efficient libarary for sparse transformer with varying token numbers (e.g., 3D point cloud).
Python
153
star
32

spconv-plus

Python
152
star
33

EfficientNeRF

The official code for "Efficient Neural Radiance Fields" in CVPR2022.
Python
152
star
34

MiSLAS

Improving Calibration for Long-Tailed Recognition (CVPR2021)
Python
144
star
35

RIVAL

[NeurIPS 2023 Spotlight] Real-World Image Variation by Aligning Diffusion Inversion Chain
Python
143
star
36

MOOD

Official PyTorch implementation of MOOD series: (1) MOODv1: Rethinking Out-of-distributionDetection: Masked Image Modeling Is All You Need. (2) MOODv2: Masked Image Modeling for Out-of-Distribution Detection.
Python
133
star
37

outpainting_srn

Wide-Context Semantic Image Extrapolation, CVPR2019
Python
131
star
38

MSAD

Multi-Scale Aligned Distillation for Low-Resolution Detection (CVPR2021)
Python
127
star
39

DeepVision3D

DeepVision3D is an open source toolbox for point-cloud understanding.
Python
119
star
40

Ref-NPR

[CVPR 2023] Ref-NPR: Reference-Based Non-PhotoRealistic Radiance Fields
Python
119
star
41

VFIformer

Video Frame Interpolation with Transformer (CVPR2022)
Python
112
star
42

Prompt-Highlighter

[CVPR 2024] Prompt Highlighter: Interactive Control for Multi-Modal LLMs
Python
112
star
43

VFF

Voxel Field Fusion for 3D Object Detection (CVPR2022)
Python
95
star
44

SMR

Self-Supervised 3D Mesh Reconstruction from Single Images (CVPR2021)
Python
91
star
45

SCGAN

The implementation of 'Image synthesis via semantic composition', ICCV2021.
Python
81
star
46

Imbalanced-Learning

Imbalanced learning tool for imbalanced recognition and segmentation
Python
79
star
47

JigsawClustering

This is the code for CVPR 2021 oral paper: Jigsaw Clustering for Unsupervised Visual Representation Learning
Python
78
star
48

AttenNorm

Attentive Normalization for Conditional Image Generation
Python
71
star
49

GFS-Seg

The official implementation of Generalized Few-shot Semantic Segmentation (CVPR 2022)
Python
63
star
50

Mask-Attention-Free-Transformer

Official Implementation for "Mask-Attention-Free Transformer for 3D Instance Segmentation"
Python
59
star
51

MoTCoder

This is the official code repository of MoTCoder: Elevating Large Language Models with Modular of Thought for Challenging Programming Tasks.
Python
58
star
52

SDSD

Seeing Dynamic Scene in the Dark: High-Quality Video Dataset with Mechatronic Alignment (ICCV2021)
Python
48
star
53

GroupContrast

[CVPR 2024] GroupContrast: Semantic-aware Self-supervised Representation Learning for 3D Understanding
42
star
54

ProposeReduce

Video Instance Segmentation with a Propose-Reduce Paradigm (ICCV 2021)
Python
41
star
55

Robust-Semantic-Segmentation

Dynamic Divide-and-Conquer Adversarial Training for Robust Semantic Segmentation (ICCV2021οΌ‰
Python
40
star
56

Mr-Ben

This is the repo for our paper "Mr-Ben: A Comprehensive Meta-Reasoning Benchmark for Large Language Models"
Python
38
star
57

BAL

BAL: Balancing Diversity and Novelty for Active Learning - Official Pytorch Implementation
Python
38
star
58

TriVol

The official code of TriVol in CVPR-2023
Python
37
star
59

MR-GSM8K

Challenge LLMs to Reason About Reasoning: A Benchmark to Unveil Cognitive Depth in LLMs
Python
37
star
60

DecoupleNet

Official implementation for our ECCV 2022 paper "DecoupleNet: Decoupled Network for Domain Adaptive Semantic Segmentation"
Python
36
star
61

Dsig

Deep Structured Instance Graph for Distilling Object Detectors (ICCV 2021)
Python
35
star
62

LBGAT

Learnable Boundary Guided Adversarial Training (ICCV2021)
Python
33
star
63

Q-LLM

This is the official repo of "QuickLLaMA: Query-aware Inference Acceleration for Large Language Models"
Python
31
star
64

AGSS-VOS

AGSS-VOS: Attention Guided Single-Shot Video Object Segmentation
Python
20
star
65

MAT

MAT: Mask-Aware Transformer for Large Hole Image Inpainting
Python
16
star
66

MSN

Memory Selection Network for Video Propagation (ECCV 2020)
Python
6
star
67

APD

Python
5
star
68

Point2Pix

The official code of Point2pix in CVPR-2023
2
star
69

TagCLIP

Python
2
star