Home

Awesome

<div align="center"> <h1> RLIPv2: Fast Scaling of Relational Language-Image Pre-training </h1> <div> <a href='https://jacobyuan7.github.io/' target='_blank'>Hangjie Yuan</a>&emsp; <a href='https://scholar.google.com/citations?user=ZO3OQ-8AAAAJ&hl=en&oi=ao' target='_blank'>Shiwei Zhang</a>&emsp; <a href='https://scholar.google.com/citations?user=cQbXvkcAAAAJ&hl=en' target='_blank'>Xiang Wang</a>&emsp; <a href='https://samuelalbanie.com/' target='_blank'>Samuel Albanie</a>&emsp; <a href='https://pynsigrid.github.io/' target='_blank'>Yining Pan</a>&emsp;<br> <!-- Yining Pan&emsp;<br> --> <a href='https://scholar.google.com/citations?user=JT8hRbgAAAAJ&hl=en' target='_blank'>Tao Feng</a>&emsp; <a href='https://scholar.google.com/citations?user=37gvStUAAAAJ&hl=en' target='_blank'>Jianwen Jiang</a>&emsp; <a href='https://scholar.google.com/citations?user=boUZ-jwAAAAJ&hl=en' target='_blank'>Dong Ni&#9993</a>&emsp; <a href='https://scholar.google.com/citations?user=16RDSEUAAAAJ&hl=en' target='_blank'>Yingya Zhang</a>&emsp; <a href='https://scholar.google.com/citations?user=7LhjCn0AAAAJ&hl=en' target='_blank'>Deli Zhao</a>&emsp; </div>

<strong>Accepted to <a href='https://iccv2023.thecvf.com/' target='_blank'>ICCV 2023</a> :partying_face:</strong>

arXiv GitHub Stars GitHub Forks Hits

</div>

colored_mesh (1)

Abstract: Relational Language-Image Pre-training (RLIP) aims to align vision representations with relational texts, thereby advancing the capability of relational reasoning in computer vision tasks. However, hindered by the slow convergence of RLIPv1 architecture and the limited availability of existing scene graph data, scaling RLIPv1 is challenging. In this paper, we propose RLIPv2, a fast converging model that enables the scaling of relational pre-training to large-scale pseudo-labelled scene graph data. To enable fast scaling, RLIPv2 introduces Asymmetric Language-Image Fusion (ALIF), a mechanism that facilitates earlier and deeper gated cross-modal fusion with sparsified language encoding layers. ALIF leads to comparable or better performance than RLIPv1 in a fraction of the time for pre-training and fine-tuning. To obtain scene graph data at scale, we extend object detection datasets with free-form relation labels by introducing a captioner (\textit{e.g.,} BLIP) and a designed Relation Tagger. The Relation Tagger assigns BLIP-generated relation texts to region pairs, thus enabling larger-scale relational pre-training. Through extensive experiments conducted on Human-Object Interaction Detection and Scene Graph Generation, RLIPv2 shows state-of-the-art performance on three benchmarks under fully-finetuning, few-shot and zero-shot settings. Notably, the largest RLIPv2 achieves 23.29mAP on HICO-DET without any fine-tuning, yields 32.22mAP with just 1% data and yields 45.09mAP with 100% data.

Todo list

Note that if you can not get access to the links provided below (OneDrive is super unstable), try using another browser, raising an issue, or contacting me by e-mail. I am happy to provide any assistance.

<!-- - [ ] πŸ•˜ Include support for inference on custom images. -->

Information before using this repo

I changed all the paths to prevent from possible information leakage. In order to run the code, you will need to configure the paths to match your own system. To do this, search for the "/PATH/TO" placeholder in the code and replace it with the appropriate file path on your system. ⭐⭐⭐Consider starring the repo! ⭐⭐⭐

Environment setup

I recommend creating a new conda environment in order to run the code. You can check scripts/create_environment.txt to acquire details on how to set up the environment.

Model outline

This repo contains the implementation of various methods to resolve HOI detection (not limited to RLIP), aiming to serve as a benchmark for HOI detection. Below methods are included in this repo:

Citation

@inproceedings{Yuan2023RLIPv2,
  title={RLIPv2: Fast Scaling of Relational Language-Image Pre-training},
  author={Yuan, Hangjie and Zhang, Shiwei and Wang, Xiang and Albanie, Samuel and Pan, Yining and Feng, Tao and Jiang, Jianwen and Ni, Dong and Zhang, Yingya and Zhao, Deli},
  booktitle={Proceedings of the IEEE/CVF International Conference on Computer Vision},
  year={2023}
}

@inproceedings{Yuan2022RLIP,
  title={RLIP: Relational Language-Image Pre-training for Human-Object Interaction Detection},
  author={Yuan, Hangjie and Jiang, Jianwen and Albanie, Samuel and Feng, Tao and Huang, Ziyuan and Ni, Dong and Tang, Mingqian},
  booktitle={Advances in Neural Information Processing Systems (NeurIPS)},
  year={2022}
}

@inproceedings{Yuan2022OCN,
  title={Detecting Human-Object Interactions with Object-Guided Cross-Modal Calibrated Semantics},
  author={Hangjie Yuan and Mang Wang and Dong Ni and Liangpeng Xu},
  booktitle={AAAI},
  year={2022}
}

Annotation preparation

DatasetSettingDownload
VGRLIPLink
COCO (pseudo)RLIPLink
Objects365 (pseudo)RLIPLink
Open ImagesFully-finetuningLink
HICO-DETFew-shot 1%, 10%Link
HICO-DETZero-shot (UC-NF, UC-RF)*Link

Note: β‘  * Zero-shot (NF) do not need any HICO-DET annotations for fine-tuning, so we only provide training annotations for the UC-NF and UC-RF setting.

Pre-training datasets preparation

1. Visual Genome

Firstly, we could download VG dataset from the official link, inclduing images Part I and Part II. (Note: If the official website is not working, you can use the link that I provide: Images and Images2.) The annotations after pre-processing could be downloaded from the link above, which is used for pre-training. Note that this is generated from scene_graphs.json file by several pre-processing steps to remove redundant triplets. Also, several settings mentioned below also need the annotations that we provide. VG dataset and its corresponding annotations should be organized as follows:

VG
 |─ annotations
 |   |β€” scene_graphs_after_preprocessing.json
 |   :
 |β€” images
 |   |β€” 2409818.jpg
 |   |β€” n102412.jpg
 :   :

2. COCO

Firstly, try downloading the COCO2017 dataset from the official link. If you want to run R-Tagger, you need to download the bounding box annotations from the website as well. If you just want to perform relational pre-training, you can merely download the pseudo-annotations for COCO2017. The dataset should be organized as follows:

COCO2017
 |β€” annotations
 |   |β€” instances_train2017.json
 |   |β€” instances_val2017.json
 |   └─ RLIPv2_train2017_threshold20.....json
 |   
 |β€” train2017
 |   |β€” 000000498666.jpg
 |   :
 |
 |β€” val2017
 |   |β€” 000000414261.jpg
 :   :

3. Objects365

Firstly, download the Objects365 dataset from the official link. This dataset contains 51 training patches and 44 validation patches, which are summed to more than 1700k images used for pre-training. Similarly, if you want to run R-Tagger, you need to download the bounding box annotations from the website as well. If you just want to perform relational pre-training, you can merely download the pseudo-annotations for Objects365. (Btw, you can try use the script in scripts/datasets folder.) The dataset should be organized as follows:

Objects365
 |β€” train 
 |   |β€” patch0
 |   |β€” patch1
 |   :
 |   |β€” patch50
 |   └─ zhiyuan_objv2_train.json
 |
 |β€” val
 |   |β€” patch0
 |   |β€” patch1
 |   :
 |   |β€” patch43
 |   └─ zhiyuan_objv2_val.json
 |
 |β€” rel_annotations
 |    └─ RLIPv2_o365trainval_Tagger2.....json
 |
 └─ image_id_to_filepath.json

Downstream dataset preparation

1. HICO-DET

HICO-DET dataset can be downloaded here. After finishing downloading, unpack the tarball (hico_20160224_det.tar.gz) to the data directory.

Instead of using the original annotations files, we use the annotation files provided by the PPDM authors. The annotation files can be downloaded from here. The downloaded annotation files have to be placed as follows.

qpic
 |─ data
 β”‚   └─ hico_20160224_det
 |       |─ annotations
 |       |   |─ trainval_hico.json
 |       |   |─ test_hico.json
 |       |   └─ corre_hico.npy
 :       :

2. V-COCO

First clone the repository of V-COCO from here, and then follow the instruction to generate the file instances_vcoco_all_2014.json. Next, download the prior file prior.pickle from here. Place the files and make directories as follows.

qpic
 |─ data
 β”‚   └─ v-coco
 |       |─ data
 |       |   |─ instances_vcoco_all_2014.json
 |       |   :
 |       |─ prior.pickle
 |       |─ images
 |       |   |─ train2014
 |       |   |   |─ COCO_train2014_000000000009.jpg
 |       |   |   :
 |       |   └─ val2014
 |       |       |─ COCO_val2014_000000000042.jpg
 |       |       :
 |       |─ annotations
 :       :

The annotation file has to be converted to the HOIA format. The conversion can be conducted as follows.

PYTHONPATH=data/v-coco \
        python convert_vcoco_annotations.py \
        --load_path data/v-coco/data \
        --prior_path data/v-coco/prior.pickle \
        --save_path data/v-coco/annotations

Note that only Python2 can be used for this conversion because vsrl_utils.py in the v-coco repository shows a error with Python3.

V-COCO annotations with the HOIA format, corre_vcoco.npy, test_vcoco.json, and trainval_vcoco.json will be generated to annotations directory.

3. Open Images v6

Open Images v6 can be downloaded from this link. We transform the annotations to the HICO-DET format, which can be downloaded from the link provided [above](## Annotation Preparation). The dataset should be organized as follows:

Open Images v6
 |
 |─ images
 |    |─ ca5267a6336b71ea.jpg
 |    :
 |
 └─ annotations

Relational Language-Image Pre-training

We provide a series of pre-trained weights for you to use. First of all, we provide weights after relational pre-training (RLIP weights) on VG+COCO+Objects365 using RLIPv2-ParSeDA.

ModelPre-training ParadigmPre-training DatasetBackboneDownload
RLIPv2-ParSeDARLIPVG+COCO+O365ResNet-50Link
RLIPv2-ParSeDARLIPVG+COCO+O365Swin-TLink
RLIPv2-ParSeDARLIPVG+COCO+O365Swin-LLink

Secondly, we provide object detection weights (OD weights) on COCO+Objects365, used to initialize RLIPv2-ParSeDA for RLIP.

ModelPre-training ParadigmPre-training DatasetBackboneDownload
RLIPv2-ParSeDAODCOCOResNet-50Link
RLIPv2-ParSeDAODCOCO+O365ResNet-50Link
RLIPv2-ParSeDAODCOCOSwin-TLink
RLIPv2-ParSeDAODCOCO+O365Swin-TLink
RLIPv2-ParSeDAODCOCOSwin-LLink
RLIPv2-ParSeDAODCOCO+O365Swin-LLink

Note that all the scripts used for pre-training RLIPv2 are presented under scripts/RLIP_ParSeDA. For instance, train_RLIP_ParSeDA_v2_mixed_vgcocoo365_swinL.sh means that this script is responsible for pre-training on mixed datasets of VG+COCO+O365 using Swin-L and RLIPv2-ParSeDA.

Downstream tasks

We provide a series of checkpoints below, which could be used for reproducing results in the paper. Note that all the scripts used for fine-tuning RLIPv2 are presented under scripts/RLIP_ParSeDA. For instance, fine_tune_RLIP_ParSeDA_v2_hico_swinL_few-shot.sh means that this script is responsible for few-shot transfer on HICO-DET using Swin-L and RLIPv2-ParSeDA.

Fully fine-tuning on HICO-DET

ModelBackboneRare / Non-Rare / FullDownload
RLIPv2-ParSeDAResNet-5029.61 / 37.10 / 35.38Link
RLIPv2-ParSeDASwin-T33.66 / 40.07 / 38.60Link
RLIPv2-ParSeDASwin-L43.23 / 45.64 / 45.09Link

Few-shot transfer on HICO-DET

ModelBackboneSettingRare / Non-Rare / FullDownload
RLIPv2-ParSeDAResNet-501%22.13 / 24.51 / 23.96Link
RLIPv2-ParSeDAResNet-5010%23.28 / 30.02 / 28.46Link
RLIPv2-ParSeDASwin-T1%24.26 / 28.92 / 27.85Link
RLIPv2-ParSeDASwin-T10%28.31 / 32.93 / 31.87Link
RLIPv2-ParSeDASwin-L1%31.89 / 32.32 / 32.22Link
RLIPv2-ParSeDASwin-L10%34.75 / 38.27 / 37.46Link

Zero-shot on HICO-DET

ModelBackboneSettingRare / Non-Rare / FullDownload
RLIPv2-ParSeDAResNet-50NF19.64 / 17.24 / 17.79Link
RLIPv2-ParSeDAResNet-50UC-RF21.45 / 35.85 / 32.97Link
RLIPv2-ParSeDAResNet-50UC-NF22.81 / 29.52 / 28.18Link
RLIPv2-ParSeDASwin-TNF21.24 / 19.47 / 19.87Link
RLIPv2-ParSeDASwin-TUC-RF26.95 / 39.92 / 37.32Link
RLIPv2-ParSeDASwin-TUC-NF21.07 / 35.07 / 32.27Link
RLIPv2-ParSeDASwin-LNF27.97 / 21.90 / 23.29Link
RLIPv2-ParSeDASwin-LUC-RF31.23 / 45.01 / 42.26Link
RLIPv2-ParSeDASwin-LUC-NF22.65 / 40.51 / 36.94Link

Fully fine-tuning on V-COCO

ModelBackboneAP_1 / AP_2Download
RLIPv2-ParSeDAResNet-5065.9 / 68.0Link
RLIPv2-ParSeDASwin-T68.8 / 70.8Link
RLIPv2-ParSeDASwin-L72.1 / 74.1Link

Fully fine-tuning on Open Images v6

ModelBackboneR@50 / wmAP_rel / wmAP_phr / score_wtdDownload
RLIPv2-ParSeDAResNet-5065.99 / 49.54 / 45.71 / 51.30Link
RLIPv2-ParSeDASwin-T68.81 / 52.70 / 48.01 / 54.05Link
RLIPv2-ParSeDASwin-L72.49 / 56.38 / 50.70 / 57.34Link

Evaluation

The mAP on HICO-DET under the Full set, Rare set and Non-Rare Set will be reported during the training process.

The results for the official evaluation of V-COCO must be obtained by the generated pickle file of detection results. You can refer to test_vcoco_official.sh for more details on running generate_vcoco_official.py.

<!-- ```shell cd /PATH/TO/RLIP python generate_vcoco_official.py \ --param_path /PATH/TO/CHECKPOINT \ --save_path vcoco.pickle \ --hoi_path /PATH/TO/VCOCO/DATA \ ``` -->

Then you should run following codes after modifying the path to get the final performance:

cd /PATH/TO/RLIP
python datasets/vsrl_eval.py

Relational pseudo-labelling

As detailed in the Figure 3 of the main paper, it involves (i) generating the captions using a captioner (i.e. BLIP), (ii) generating a relation candidate set and (iii) assigning relation texts to region pairs via an R-Tagger.

Acknowledgement

Part of this work's implemention refers to several prior works including RLIP, OCN, QPIC, CDN, DETR, DDETR, MDETR and GLIP.