jiaosiyu1999 / MAFT

46 stars 2 forks source link

Learning Mask-aware CLIP Representations for Zero-Shot Segmentation

PWC PWC PWC PWC PWC

This is the official implementation of our conference paper : "Learning Mask-aware CLIP Representations for Zero-Shot Segmentation" (NeurIPS 2023).

:fire: News: Our paper MAFT+ is accepted to ECCV 2024 oral!

Introduction

Recently, pre-trained vision-language models have been increasingly used to tackle the challenging zero-shot segmentation task. To maintain the CLIP's zero-shot transferability, previous practices favour to freeze CLIP during training. However, in the paper, we reveal that CLIP is insensitive to different mask proposals and tends to produce similar predictions for various mask proposals of the same image. This issue mainly relates to the fact that CLIP is trained with image-level supervision. To alleviate this issue, we propose a simple yet effective method, named Mask-aware Fine-tuning (MAFT). Specifically, Image-Proposals CLIP Encoder (IP-CLIP Encoder) is proposed to handle arbitrary numbers of image and mask proposals simultaneously. Then, mask-aware loss and self-distillation loss are designed to fine-tune IP-CLIP Encoder, ensuring CLIP is responsive to different mask proposals while not sacrificing transferability. In this way, mask-aware representations can be easily learned to make the true positives stand out. Notably, our solution can seamlessly plug into most existing methods without introducing any new parameters during the fine-tuning process.

Tab of Content

Installation

  1. Clone the repository
    git clone https://github.com/jiaosiyu1999/MAFT.git
  2. Navigate to the project directory
    cd MAFT
  3. Install the dependencies
    bash install.sh
    cd freeseg/modeling/heads/ops
    sh make.sh

Data Preparation

See Preparing Datasets for MAFT. The data should be organized like:

datasets/
  ade/
      ADEChallengeData2016/
        images/
        annotations_detectron2/
      ADE20K_2021_17_01/
        images/
        annotations_detectron2/
  coco/
        train2017/
        val2017/
        stuffthingmaps_detectron2/
  VOCdevkit/
     VOC2012/
        images_detectron2/
        annotations_ovs/      
    VOC2010/
        images/
        annotations_detectron2_ovs/
            pc59_val/
            pc459_val/      

Usage

  1. step2 Fine-tune CLIP Image Encoder with MAFT: (Note: the the step1 model should be load.)
    python train_net.py --config-file configs/coco-stuff-164k-156/mask2former_maft.yaml --num-gpus 4
    • Inference Demo with Pre-trained Models

      We provide demo/demo.py that is able to demo builtin configs. Run it with:

      python demo/demo.py \
      --input input1.jpg input2.jpg \
      [--other-options]
      --opts MODEL.WEIGHTS /path/to/checkpoint_file

      For example, evaluate our pre-trained MAFT_Vitb.pt model:

      # 1. Download MAFT-ViT-B.
      # 2. put it at `out/MAFT_Vitb.pt`.
      # 3. run demo:
      python demo/demo.py  --input im.png

Cite

If you find it helpful, you can cite our paper in your work.

@inproceedings{jiao2023learning,
  title={Learning Mask-aware CLIP Representations for Zero-Shot Segmentation},
  author={Jiao, Siyu and Wei, Yunchao and Wang, Yaowei and Zhao, Yao and Shi, Humphrey},
  booktitle={Thirty-seventh Conference on Neural Information Processing Systems},
  year={2023}
}