Prototype-based Incremental Few-Shot Semantic Segmentation

Related tags

Deep Learning FSS
Overview

Prototype-based Incremental Few-Shot Semantic Segmentation

Fabio Cermelli, Massimiliano Mancini, Yongqin Xian, Zeynep Akata, Barbara Caputo -- BMVC 2021 (Poster) Link

Official PyTorch Implementation

teaser

Semantic segmentation models have two fundamental weaknesses: i) they require large training sets with costly pixel-level annotations, and ii) they have a static output space, constrained to the classes of the training set. Toward addressing both problems, we introduce a new task, Incremental Few-Shot Segmentation (iFSS). The goal of iFSS is to extend a pretrained segmentation model with new classes from few annotated images and without access to old training data. To overcome the limitations of existing models iniFSS, we propose Prototype-based Incremental Few-Shot Segmentation (PIFS) that couples prototype learning and knowledge distillation. PIFS exploits prototypes to initialize the classifiers of new classes, fine-tuning the network to refine its features representation. We design a prototype-based distillation loss on the scores of both old and new class prototypes to avoid overfitting and forgetting, and batch-renormalization to cope with non-i.i.d.few-shot data. We create an extensive benchmark for iFSS showing that PIFS outperforms several few-shot and incremental learning methods in all scenarios.

method

How to run

Requirements

We have simple requirements: The main requirements are:

python > 3.1
pytorch > 1.6

If you want to install a custom environment for this codce, you can run the following using conda:

conda install pytorch torchvision cudatoolkit=10.1 -c pytorch
conda install tensorboard
conda install jupyter
conda install matplotlib
conda install tqdm
conda install imageio

pip install inplace-abn
conda install -c conda-forge pickle5

Datasets

In the benchmark there are two datasets: Pascal-VOC 2012 and COCO (object only). For the COCO dataset, we followed the COCO-stuff splits and annotations, that you can see here.

To download dataset, follow the scripts: data/download_voc.sh, data/download_coco.sh

To use the annotations of COCO-Stuff in our setting, you should preprocess it by running the provided script.
Please, remember to change the path in the script before launching it! python data/coco/make_annotation.py

Finally, if your datasets are in a different folder, make a soft-link from the target dataset to the data folder. We expect the following tree:

/data/voc/dataset
    /annotations
        <Image-ID>.png
    /images
        <Image-ID>.png
        
/data/coco/dataset
    /annotations
        /train2017
            <Image-ID>.png
        /val2017
            <Image-ID>.png
    /images
        /train2017
            <Image-ID>.png
        /val2017
            <Image-ID>.png

ImageNet Pretrained Models

After setting the dataset, you download the models pretrained on ImageNet using InPlaceABN. Download the ResNet-101 model (we only need it but you can also download other networks if you want to change it). Then, put the pretrained model in the pretrained folder.

Run!

We provide different scripts to run the experiments (see run folder). In the following, we describe the basic structure of them.

First, you should run the base step (or step 0).

exp --method FT --name FT --epochs 30 --lr 0.01 --batch_size 24

In this example, we are running the fine-tuning method (FT). For other methods (COS, SPN, DWI, RT) you can change the method name. WI and PIFS rely on the COS in the step 0, while FT, AMP, LWF, ILT, MIB rely on the FT one.

After this, you can run the incremental steps. There are a few options: (i) the task, (ii) the number of images (n_shot), and (iii) the sampling split (i_shot).

i) The list of tasks is:

voc:
    5-0, 5-1, 5-2, 5-3
coco:
    20-0, 20-1, 20-2, 20-3

For multi-step, you can append an m after the task (e.g., 5-0m)

ii) We tested 1, 2, and 5 shot. You can specify it with the nshot option.

iii) We used three random sampling. You can specify it with the ishot option.

The training will produce both an output on the terminal and it will log on tensorboard at the logs/<Exp_Name> folder. After the training, it will append a row in the csv file logs/results/<dataset>/<task>.csv.

Qualitative Results

qual-voc qual-coco

Cite us!

Please, cite the following article when referring to this code/method.

@InProceedings{cermelli2020prototype,
  title={Prototype-based Incremental Few-Shot Semantic Segmentation },
  author={Cermelli, Fabio and Mancini, Massimiliano and Xian, Yongqin and Akata, Zeynep and Caputo, Barbara},
  booktitle={Proceedings of the 32nd British Machine Vision Conference},
  month={November},
  year={2021}
}
Comments
  • Bad results on COCO dataset

    Bad results on COCO dataset

    Sorry to bother u, when I reproduct on Voc, it's the same results on Voc datasets you gave in your paper. But when I reproduct your methods on the CoCo dataset, using the exactly same hyperparameters, the results are much lower than those in the paper. I have tried a lot of time, but it always does. I can't figure out that problem, could you please give me some advice? image image Above is the shell script of PIFS* running on the strict incremental few shot setting.

    opened by zhangyuxuan321 5
  • Supplementary materials

    Supplementary materials

    In the paper posted on arxiv, it seems that many details are omitted due to space limitations and are reported in the supplementary materials. I was wondering if it is possible to share the supplementary materials here? They would be very useful for reproduction purpose.

    opened by RogerQi 3
  • Different weight imprinting result in table 2 and table 3 and unable to run evaluation script

    Different weight imprinting result in table 2 and table 3 and unable to run evaluation script

    Hello,

    First of all - thanks for open-sourcing the great work!

    I have a question about the WI (weight imprinting) result of COCO-SS in table 2 and COCO-MS in table 3. Aren't they supposed to be close? As I understand how WI works - WI does not change feature extractor and new classifier weights are appended to the classifier weights using masked averaged pooling on provided samples. Therefore, if the samples provided to the model are the same, WI result should be consistent whether or not the setting is single-step (SS) or multi-step (MS). However, for instance, in table 2, the WI method gets 8.7 novel IoU in 5-shot case. However in table 3, the WI method gets 10.3 novel IoU in 5-shot case, which seems to be a significant improvement than table 2.

    What are the factors here that cause the performance difference? Is it because of randomness of samples or is there some other factor that I did not consider?

    I tried to run ./run/coco-ms.sh to understand what is happening. I use task 20-1m as an example. I did base stage training on COS and commented out all experiments except the WI one. But I got the following exception - it seems to have something to do with the class_to_img_id mapping but I followed the instruction exactly to prepare the dataset.

    ➜  FSS git:(master) ✗ ./run/coco-ms.sh
    2365
    2021-12-16 05:11:16.975790: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0
    Device: cuda:0
    Dataset: coco, Train set: 5, Val set: 5000
    Total batch size is 5
    Train loader contains 1 iterations per epoch, multiplied by 20
    Total iterations are 1, corresponding to 0 epochs
    Backbone: resnet101
    [!] Model made with pre-trained
    [!] Previous model loaded from checkpoints/step/20-1m-coco/COS_0.pth
    Warm up lap!
    [!] Train from the beginning of the task
    tensor([[61]])
    Cooling down...
    [!] Checkpoint saved.
    *** Test the model on all seen classes...
    Dataset: coco, Test set: 5000
    *** Model restored from checkpoints/step/20-1m-coco/WI-s1-i0_1.pth
    Validation, Class Loss=0.6551916599273682
    Done test on all
    *** End of Test on all, Total Loss=0.6551916599273682
    
    Total samples: 5000.000000
    Overall Acc: 0.635754
    Mean Acc: 0.481951
    Mean Precision: 0.280138
    FreqW Acc: 0.486665
    Mean IoU: 0.276608
    Class IoU:
    	B: 0.2638237064899347
    	N: 0.045324342936183426
    Class Acc:
    	B: 0.460117586250249
    	N: 0.07358551581904954
    Class Prec:
    	B: 0.2946033495916806
    	N: 0.1036611978337707
    
    Closing the Logger.
    2021-12-16 05:15:15.699890: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0
    Device: cuda:0
    Dataset: coco, Train set: 5, Val set: 5000
    Total batch size is 5
    Train loader contains 1 iterations per epoch, multiplied by 20
    Total iterations are 1, corresponding to 0 epochs
    Backbone: resnet101
    [!] Model made with pre-trained
    [!] Previous model loaded from checkpoints/step/20-1m-coco/WI-s1-i0_1.pth
    Warm up lap!
    Traceback (most recent call last):
      File "run.py", line 301, in <module>
        main(opts)
      File "run.py", line 157, in main
        model.warm_up(train_dst_no_aug)
      File "/home/roger/reproduction/FSS/methods/trainer.py", line 177, in warm_up
        self.warm_up_(dataset, epochs)
      File "/home/roger/reproduction/FSS/methods/imprinting.py", line 113, in warm_up_
        assert torch.any(count != 0), "Error, a novel class has no pixels!"
    AssertionError: Error, a novel class has no pixels!
    Killing subprocess 168145
    Traceback (most recent call last):
      File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
        exec(code, run_globals)
      File "/usr/local/lib/python3.8/dist-packages/torch/distributed/launch.py", line 340, in <module>
        main()
      File "/usr/local/lib/python3.8/dist-packages/torch/distributed/launch.py", line 326, in main
        sigkill_handler(signal.SIGTERM, None)  # not coming back
      File "/usr/local/lib/python3.8/dist-packages/torch/distributed/launch.py", line 301, in sigkill_handler
        raise subprocess.CalledProcessError(returncode=last_return_code, cmd=cmd)
    subprocess.CalledProcessError: Command '['/usr/bin/python3', '-u', 'run.py', '--local_rank=0', '--num_workers', '4', '--dataset', 'coco', '--task', '20-1m', '--method', 'WI', '--name', 'WI', '--iter', '0', '--lr', '0.001', '--ishot', '0', '--input_mix', 'novel', '--val_interval', '1000', '--ckpt_interval', '5', '--no_pooling', '--step', '2', '--nshot', '1']' returned non-zero exit status 1.
    
    
    opened by RogerQi 3
  • Which COCO/VOC settings are used in the paper

    Which COCO/VOC settings are used in the paper

    Hi, the paper considers 15 and 60 of base classes, and 5 and 20 of new classes for VOC and COCO, respectively. However, there are many settings VOC (15-5, 5-0, etc.) or COCO (20-0, 20-1, etc.) have 15-5 and 60-20 base and new classes.

    Could you please tell me which VOC/COCO setting did you use in the paper? And if possible, the id of ishot for such results.

    opened by HieuPhan33 3
  • Where is the implementation of Eqn.3 in the code?

    Where is the implementation of Eqn.3 in the code?

    Hi,

    Thanks for releasing the code. I have a question in the method "PIFS". In the incremental stage, the classifier of the new classes are initialized via feature prototype (Eqn.3 in the paper). But I didn't find this implementation in the code corresponding to "PIFS".

    Based on my understanding, the method of "PIFS" use the Trainer in the methods/trainer.py as the model. But the Trainer didn't provide the implementation of Eqn.3.

    Could you please help me pointing out the implementation of Eqn.3 for PIFS? Thank you!

    opened by Pixie412 2
  • how to run the code in single gpu?

    how to run the code in single gpu?

    Hi, Thanks for releasing the code. I want to run your code in single gpu. I am trying running this command: "python run.py --method COS --name COS --epochs 30 --lr 0.01 --batch_size 24", but it gives this error: image

    Could you please give some suggestion on how to run the code in the single gpu? Thanks!

    opened by Pixie412 2
  • Question about the non-strict IL setting

    Question about the non-strict IL setting

    Hi, In the non-strict IL setting, which the paper adopts, is it possible an image appears in both the base stage training and incremental stage training? For example, an image contains both the annotation of the base classes and new classes. The image is sampled in the base step to learn the base classes, and is also sampled in the incremental step to learn the new class.

    opened by Pixie412 2
  • Inplace_abn not work for nshot=1

    Inplace_abn not work for nshot=1

    Hi, when training for nshot=1, I encounter the error inplace_abn is trying to compute batch statistics, but the input tensor only contains a single sample per channel.

    The BatchNorm seems to raise error when batch size=1. Could you please suggest a solution for this problem?

    Thanks.

    opened by HieuPhan33 2
  • AttributeError: 'Namespace' object has no attribute 'pixel_imprinting'

    AttributeError: 'Namespace' object has no attribute 'pixel_imprinting'

    Hi, When I train WI on step 1 with the following command: python -m torch.distributed.launch --master_port 6006 --nproc_per_node=1 run.py --method WI --name WIT --iter $2000 --lr 0.0001 --task 20-0 --dataset coco --ishot 3 --input_mix novel --val_interval 1000 --ckpt_interval 5 --step 1 --nshot 5 --step_ckpt ${path}/COS_0.pth

    I have the following error: NameSpace object has no attribute pixel_imprinting on line 70 in methods/imprinting.py

    opened by HieuPhan33 2
  • AssertionError: a novel class has no pixels - Label id mismatch

    AssertionError: a novel class has no pixels - Label id mismatch

    Hi, I execute the bash script run.py for task 7mc on coco dataset.

    When training on step 1 with ns=2, I get ​an assertion error on line 176 in methods/imprinting.py: AssertionError: Error, a novel class has no pixels.

    Here are some of my inspections:

    1. In imprinting.py script, the new_classes is [74] which corresponds to the total number of classes in the previous step;
    2. However, the unique labels in the sample are [18, 19, 255] for is=2, [19, 255] for is=3. In other words, we only select image with label 19 on coco-7mc-step1;
    3. In task.py, the actual new class id is 21;

    So I doubt that the issue could be the way we filter images by labels in dataset/dataset.py.

    I would appreciate if you provide some help. Thank you in advance.

    opened by HieuPhan33 2
  • overlapped or disjoint?

    overlapped or disjoint?

    if task.disjoint: # disjoint or overlapped ? for cl, img_set in self.full_data.class_to_images.items(): if cl not in self.labels and (cl != 0): idxs = idxs.difference(img_set)

    I think it is the overlapped setting, not disjoint? Is it?

    opened by EDGSCOUT 1
Owner
Fabio Cermelli
My research interest in AI includes Computer vision and Reinforcement learning.
Fabio Cermelli
Audio-Visual Generalized Few-Shot Learning with Prototype-Based Co-Adaptation

Audio-Visual Generalized Few-Shot Learning with Prototype-Based Co-Adaptation The code repository for "Audio-Visual Generalized Few-Shot Learning with

Kaiaicy 3 Jun 27, 2022
[CVPR 2021] Few-shot 3D Point Cloud Semantic Segmentation

Few-shot 3D Point Cloud Semantic Segmentation Created by Na Zhao from National University of Singapore Introduction This repository contains the PyTor

null 117 Dec 27, 2022
Official code for "Simpler is Better: Few-shot Semantic Segmentation with Classifier Weight Transformer. ICCV2021".

Simpler is Better: Few-shot Semantic Segmentation with Classifier Weight Transformer. ICCV2021. Introduction We proposed a novel model training paradi

Lucas 103 Dec 14, 2022
[CVPR'22] Weakly Supervised Semantic Segmentation by Pixel-to-Prototype Contrast

wseg Overview The Pytorch implementation of Weakly Supervised Semantic Segmentation by Pixel-to-Prototype Contrast. [arXiv] Though image-level weakly

Ye Du 96 Dec 30, 2022
CVPR2022 (Oral) - Rethinking Semantic Segmentation: A Prototype View

Rethinking Semantic Segmentation: A Prototype View Rethinking Semantic Segmentation: A Prototype View, Tianfei Zhou, Wenguan Wang, Ender Konukoglu and

Tianfei Zhou 239 Dec 26, 2022
Few-NERD: Not Only a Few-shot NER Dataset

Few-NERD: Not Only a Few-shot NER Dataset This is the source code of the ACL-IJCNLP 2021 paper: Few-NERD: A Few-shot Named Entity Recognition Dataset.

THUNLP 319 Dec 30, 2022
Code for T-Few from "Few-Shot Parameter-Efficient Fine-Tuning is Better and Cheaper than In-Context Learning"

T-Few This repository contains the official code for the paper: "Few-Shot Parameter-Efficient Fine-Tuning is Better and Cheaper than In-Context Learni

null 220 Dec 31, 2022
Pytorch implementation of few-shot semantic image synthesis

Few-shot Semantic Image Synthesis Using StyleGAN Prior Our method can synthesize photorealistic images from dense or sparse semantic annotations using

null 40 Sep 26, 2022
Recall Loss for Semantic Segmentation (This repo implements the paper: Recall Loss for Semantic Segmentation)

Recall Loss for Semantic Segmentation (This repo implements the paper: Recall Loss for Semantic Segmentation) Download Synthia dataset The model uses

null 32 Sep 21, 2022
Code for our method RePRI for Few-Shot Segmentation. Paper at http://arxiv.org/abs/2012.06166

Region Proportion Regularized Inference (RePRI) for Few-Shot Segmentation In this repo, we provide the code for our paper : "Few-Shot Segmentation Wit

Malik Boudiaf 138 Dec 12, 2022
Official PyTorch Implementation of Hypercorrelation Squeeze for Few-Shot Segmentation, arXiv 2021

Hypercorrelation Squeeze for Few-Shot Segmentation This is the implementation of the paper "Hypercorrelation Squeeze for Few-Shot Segmentation" by Juh

Juhong Min 165 Dec 28, 2022
The implementation of PEMP in paper "Prior-Enhanced Few-Shot Segmentation with Meta-Prototypes"

Prior-Enhanced network with Meta-Prototypes (PEMP) This is the PyTorch implementation of PEMP. Overview of PEMP Meta-Prototypes & Adaptive Prototypes

Jianwei ZHANG 8 Oct 14, 2021
Code for 'Self-Guided and Cross-Guided Learning for Few-shot segmentation. (CVPR' 2021)'

SCL Introduction Code for 'Self-Guided and Cross-Guided Learning for Few-shot segmentation. (CVPR' 2021)' We evaluated our approach using two baseline

null 34 Oct 8, 2022
PFENet: Prior Guided Feature Enrichment Network for Few-shot Segmentation (TPAMI).

PFENet This is the implementation of our paper PFENet: Prior Guided Feature Enrichment Network for Few-shot Segmentation that has been accepted to IEE

DV Lab 230 Dec 31, 2022
The code is for the paper "A Self-Distillation Embedded Supervised Affinity Attention Model for Few-Shot Segmentation"

SD-AANet The code is for the paper "A Self-Distillation Embedded Supervised Affinity Attention Model for Few-Shot Segmentation" [arxiv] Overview confi

cv516Buaa 9 Nov 7, 2022
PixelPick This is an official implementation of the paper "All you need are a few pixels: semantic segmentation with PixelPick."

PixelPick This is an official implementation of the paper "All you need are a few pixels: semantic segmentation with PixelPick." [Project page] [Paper

Gyungin Shin 59 Sep 25, 2022
Byte-based multilingual transformer TTS for low-resource/few-shot language adaptation.

One model to speak them all ?? Audio Language Text ▷ Chinese 人人生而自由,在尊严和权利上一律平等。 ▷ English All human beings are born free and equal in dignity and rig

Mutian He 60 Nov 14, 2022
The Few-Shot Bot: Prompt-Based Learning for Dialogue Systems

Few-Shot Bot: Prompt-Based Learning for Dialogue Systems This repository includes the dataset, experiments results, and code for the paper: Few-Shot B

Andrea Madotto 103 Dec 28, 2022
The official implementation of the CVPR 2021 paper FAPIS: a Few-shot Anchor-free Part-based Instance Segmenter

FAPIS The official implementation of the CVPR 2021 paper FAPIS: a Few-shot Anchor-free Part-based Instance Segmenter Introduction This repo is primari

Khoi Nguyen 8 Dec 11, 2022