Home

Awesome

Annealing-based-Label-Transfer-Learning-for-Open-World-Object-Detection

Introduction

This repository is the official PyTorch implemetation of paper "Annealing-based-Label-Transfer-Learning-for-Open-World-Object-Detection".

image

<!--- <p align="center"> <img src="./docs/framework.gif" alt="framework"> </p> -->

NOTE:

Key Code

Our key codes of the RCNN-based and DETR-based model are listed below, respectively:

<html> <table style="width: 100%;"> <tr> <td style="width: 50%;"> <!--左侧内容--> <pre><code> <strong>RCNN-Based</strong> . └── detectron2 ├── data │   └── LabelTrans_common.py └── modeling ├── meta_arch │ └── rcnn.py    └── roi_heads       └── AnneallingLT_out.py </code></pre> </td> <td style="width: 50%;"> <!--右侧内容--> <pre><code> <strong>DETR-Based</strong> . ├── configs │   └── new1026 ├── main_open_world.py └── models    └── AnneallingLT_detr.py ├── requirements.txt └── scripts </code></pre> </td> </tr> </table> </html> <!--- - The Label-Transfer learning method can be found in the [detectron2/data/LabelTrans_common.py](https://github.com/DIG-Beihang/ALL-OWOD/blob/master/detectron2/data/LabelTrans_common.py#L46). The Sawtooth Annealing Scheduling strategy is provided in [detectron2/modeling/roi_heads/AnnealingLT_out.py](https://github.com/DIG-Beihang/ALL-OWOD/blob/master/detectron2/modeling/roi_heads/AnneallingLT_out.py#L312) [detectron2/modeling/roi_heads/AnnealingLT_heads.py](https://github.com/DIG-Beihang/ALL-OWOD/blob/master/detectron2/modeling/roi_heads/AnneallingLT_heads.py) and the Annealing classification loss is defined in - In the code of DETR-based model, both the Label-Transfer learning method and the Sawtooth Annealing Scheduling strategy are provided in [models/AnnealingLT_detr.py](https://github.com/DIG-Beihang/ALL-OWOD/blob/detr-based/models/AnneallingLT_detr.py#L337). --> <!--- - First, modify the annotation of the data, we give all data an additional unknown class label, the code can be found [here](https://github.com/DIG-Beihang/Annealing-based-Label-Transfer-Learning-for-Open-World-Object-Detection/blob/ade50266435d699ece227192e08a46c26d57784f/detectron2/data/LabelTrans_common.py#L52) ``` if self._map_func.is_train: data['instances'].ori_classes = data['instances'].gt_classes.clone() data['instances'].gt_classes[:] = 80 ``` - Second, during the extending phase of the training, which is controlled by the cfg.OWOD.COOLING parameter, we need to freeze all parameters except for the classifier, and the specific code is [here](https://github.com/DIG-Beihang/ALL-OWOD/blob/c8bfcc8074407370184a48af58e20cdb22aa1aac/detectron2/engine/defaults.py#L285). Note that the optimizer in Detectron2 is initialized after this step, and during initialization, it ignores the parameters that do not have gradients. ``` if cfg.OWOD.COOLING: for name, param in model.named_parameters(): if 'cls_score' not in name: param.requires_grad = False ``` - Finally, after calling the new loss function, you can start the training! Code can be found [here](https://github.com/DIG-Beihang/ALL-OWOD/blob/c8bfcc8074407370184a48af58e20cdb22aa1aac/detectron2/modeling/roi_heads/AnneallingLT_out.py#L334). ``` def mixup_loss(self): if self._no_instances: return 0.0 * self.pred_class_logits.sum() else: self._log_accuracy() self.pred_class_logits[:, self.invalid_class_range] = -10e10 storage = get_event_storage() if self.cooling: lam = max(self.peak - (storage.iter / self.cool_iter), 0) else: lam = 0 loss_pred = \ (1-lam) * F.cross_entropy(self.pred_class_logits, self.ori_classes, reduction="mean", weight=self.weights) + \ lam*F.cross_entropy(self.pred_class_logits, self.gt_classes, reduction="mean", weight=self.weights) return loss_pred ``` -->

Install for RCNN-Based

Requirements

<!--- - Install detectron2, please refer to [INSTALL.md](./INSTALL.md). -->

Data Preparation for ORE split

Install for DETR-Based

Requirements

We have trained and tested our models on Ubuntu 16.0, CUDA 11.1, GCC 5.4, Python 3.7

conda create -n owdetr python=3.7
conda activate owdetr
conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=11.1 -c pytorch
pip install -r requirements.txt

Compiling CUDA operators

cd ./models/ops
sh ./make.sh
# unit test (should see all checking is True)
python test.py

Data Preparation for ORE split

OW-DETR/
└── data/
    └── VOC2007/
        └── OWOD/
        	├── JPEGImages
        	├── ImageSets
        	└── Annotations

Pretrained weights

You can download the pre-trained backbone network models and the best OWOD models trained by ours methods for Task t1-t4 here.

Usage

Training

bash scripts/train_t2.sh
bash scripts/train_t2_ft.sh
bash scripts/train_t2_extending.sh

Evaluation

Citation

If this work helps your research, please consider citing:

@inproceedings{ma2021annealing,
    title={Annealing-based Label-Transfer Learning for Open World Object Detection}, 
    author={Ma, Yuqing and Li, Hainan and Zhang, Zhange and Guo, Jinyang and 
    Zhang, Shanghang and Gong, Ruihao and Liu, Xianglong},
    booktitle={CVPR},
    year={2023}
}