Home

Awesome

<div align="center"> <h2>【CVPR'2023γ€‘πŸš΄ BIKE: Bidirectional Cross-Modal Knowledge Exploration for Video Recognition with Pre-trained Vision-Language Models </h2>

Conference arXiv

<!-- <h3><a href="https://arxiv.org/abs/2301.00182">Bidirectional Cross-Modal Knowledge Exploration for Video Recognition with Pre-trained Vision-Language Models</a></h3> -->

Wenhao Wu<sup>1,2</sup>, Xiaohan Wang<sup>3</sup>, Haipeng Luo<sup>4</sup>, Jingdong Wang<sup>2</sup>, Yi Yang<sup>3</sup>, Wanli Ouyang<sup>5,1</sup>

<sup>1</sup>The University of Sydney, <sup>2</sup>Baidu, <sup>3</sup>ZJU, <sup>4</sup>UCAS, <sup>5</sup>Shanghai AI Lab

</div>

PWC PWC PWC PWC PWC PWC PWC PWC PWC

This is the official implementation of our 🚴 BIKE (BIdirectional Knowledge Exploration), which leverages cross-modal bridge to enhance video recognition by exploring bidirectional knowledge.

<details open><summary>πŸ“£ I also have other cross-modal video projects that may interest you ✨. </summary><p>

Revisiting Classifier: Transferring Vision-Language Models for Video Recognition<br> Wenhao Wu, Zhun Sun, Wanli Ouyang <br> Conference Journal github

Cap4Video: What Can Auxiliary Captions Do for Text-Video Retrieval?<br> Wenhao Wu, Haipeng Luo, Bo Fang, Jingdong Wang, Wanli Ouyang <br> Accepted by CVPR 2023 as 🌟Highlight🌟 | Conference github<br>

</p></details>

News

Overview

🚴BIKE explores bidirectional cross-modal knowledge from the pre-trained vision-language model (e.g., CLIP) to introduce auxiliary attributes and category-dependent temporal saliency for improved video recognition.

BIKE

Content

<a name="prerequisites"></a>

Prerequisites

<details><summary>The code is built with following libraries. </summary><p> </p></details>

<a name="data-preparation"></a>

Data Preparation

Video Loader

(Recommend) To train all of our models, we extract videos into frames for fast reading. Please refer to MVFNet repo for the detailed guide of dataset processing.
The annotation file is a text file with multiple lines, and each line indicates the directory to frames of a video, total frames of the video and the label of a video, which are split with a whitespace.

<details open><summary>Example of annotation</summary>
abseiling/-7kbO0v4hag_000107_000117 300 0
abseiling/-bwYZwnwb8E_000013_000023 300 0
</details>

(Optional) We can also decode the videos in an online fashion using decord. This manner should work but are not tested. All of the models offered have been trained using offline frames.

<details><summary>Example of annotation</summary>
  abseiling/-7kbO0v4hag_000107_000117.mp4 0
  abseiling/-bwYZwnwb8E_000013_000023.mp4 0
</details>

Annotation

Annotation information consists of two parts: video label, and category description.

<a name="model-zoo"></a>

πŸ“± Model Zoo

Training GPU Memory

During our training, we maintain a total batch size of 256. If your machine's GPU memory is not enough, you can reduce the batch size to reduce the memory usage. It is best to correspondingly increase the value of "grad_accumulation_steps" in the config file.

ArchitectureInputBatch Size (per GPU) x 8GPUsMem. (per GPU)
ViT-B/328x224<sup>2</sup>32 x 8 = 2566G
ViT-B/168x224<sup>2</sup>32 x 8 = 2569G
ViT-L/148x224<sup>2</sup>32 x 8 = 25618G
ViT-L/1416x224<sup>2</sup>32 x 8 = 25629G

Kinetics-400

ArchitectureInputViewsTop-1(%)checkpointTrain logconfig
ViT-B/32 <sup>V+A</sup>8x224<sup>2</sup>1x181.4Scorelogconfig
ViT-B/168x224<sup>2</sup>4x384.0Githublogconfig
ViT-L/14*8x224<sup>2</sup>4x387.4OneDrivelogconfig
ViT-L/1416x224<sup>2</sup>4x388.1OneDrivelogconfig
ViT-L/148x336<sup>2</sup>4x388.3OneDrivelogconfig
ViT-L/1416x336<sup>2</sup>4x388.7OneDrivelogconfig
<!-- | ViT-L/14 | 32x336<sup>2</sup> | 4x3 | xx.x | [OneDrive]() | [log](exps/k400/ViT-L/14-336px/32f/log.txt) | [config](configs/k400/k400_train_rgb_vitl-14-336-f32.yaml) | -->

Untrimmed Video Recognition: ActivityNet

ArchitectureInputViewsTop-1 (%)mAP (%)checkpointTrain logconfig
ViT-L/1416x224<sup>2</sup>4x194.496.3OneDrivelogconfig
ViT-L/1416x336<sup>2</sup>4x194.796.1OneDrivelogconfig

Multi-label Action Recognition: Charades

ArchitectureInputViewsmAP (%)checkpointTrain logconfig
ViT-L/1416x336<sup>2</sup>4x150.7OneDrivelogconfig

UCF-101

ArchitectureInputViewsTop-1 (%)checkpointTrain logconfig
ViT-L/1416x224<sup>2</sup>1x198.7OneDrivelogconfig
ViT-L/1416x336<sup>2</sup>1x198.9OneDrivelogconfig

HMDB-51

ArchitectureInputViewsTop-1 (%)checkpointTrain logconfig
ViT-L/1416x224<sup>2</sup>1x182.9OneDrivelogconfig
ViT-L/1416x336<sup>2</sup>1x184.3OneDrivelogconfig

<a name="training"></a>

πŸš€ Training

This implementation supports Multi-GPU DistributedDataParallel training, which is faster and simpler than DataParallel training. Note: The JSON file containing the attributes is already available at https://github.com/whwu95/BIKE/releases/tag/v1.0.

  1. Single Machine: To train our model on Kinetics-400 with 8 GPUs in Single Machine, you can run:
# We train the 8 Frames ViT-B/32 video model (i.e., video branch).
sh scripts/run_train.sh  configs/k400/k400_train_rgb_vitb-32-f8.yaml

# We train the video branch and attributes branch.
sh scripts/run_co_train.sh  configs/k400/k400_train_video_attr_vitb-32-f8.yaml
<details><summary>2. Mulitple Machines: We also provide the script to train larger model with Mulitple Machines (e.g., 2 nodes have 16 GPUs).</summary>
# For example, we train the 8 Frames ViT-L/14-336 with 2 machines as follows:
# For first machine, you need to set the ip of your first machine as the --master_addr, --nnodes is 2.
# Compared with the Single-Machine training script, only one node_id needs to be added.
sh scripts/run_train_multinodes.sh configs/k400/configs/k400/k400_train_rgb_vitl-14-336-f8.yaml 0

# For second machine, --master_addr is still the ip of your first machine
sh scripts/run_train_multinodes.sh configs/k400/configs/k400/k400_train_rgb_vitl-14-336-f8.yaml 1
</details> <details><summary>3. Few-shot Recognition: To train our model under Few-shot scenario, you just need to add one line in the general config file.</summary>
# You can refer to config/k400/k400_few_shot.yaml
data: 
    ...  # general configurations
    shot: 2  # i.e., 2-shot setting
</details>

<a name="testing"></a>

⚑ Testing

We support single-view validation (default) and multi-view (4x3 views) validation.

# The testing command for obtaining top-1/top-5 accuracy.
sh scripts/run_test.sh Your-Config.yaml Your-Trained-Model.pt

# The command for zero-shot evaluation is similar.
sh scripts/run_test_zeroshot.sh Your-Config.yaml Your-Trained-Model.pt

We provide more examples of testing commands below.

<details open><summary>General / Few-shot Video Recognition</summary>
# Efficient Setting: Single view evaluation. 
# E.g., ViT-L/14 8 Frames on Kinetics-400. You should get around 86.5% top-1 accuracy. 
sh scripts/run_test.sh  configs/k400/k400_train_rgb_vitl-14-f8.yaml exps/k400/ViT-L/14/8f/k400-vit-l-14-f8.pt

# Accurate Setting: Multi-view evalition (4clipsx3crops).
# You should get around 87.4% top-1 accuracy. 
sh scripts/run_test.sh  configs/k400/k400_train_rgb_vitl-14-f8.yaml exps/k400/ViT-L/14/8f/k400-vit-l-14-f8.pt --test_crops 3  --test_clips 4

# Test the Charades dataset using the mAP metric. You should achieve around 50.7 mAP.
sh scripts/run_test_charades.sh configs/charades/charades_k400_finetune_336.yaml exps/charades/ViT-L/14-336px/16f/charades-vit-l-336-f16.pt --test_crops 1  --test_clips 4

# Test the ActivityNet dataset using top1 and mAP metric. You should achieve around 96.3 mAP.
sh scripts/run_test.sh configs/anet/anet_k400_finetune.yaml exps/anet/ViT-L/14/f16/anet-vit-l-f16.pt --test_crops 1  --test_clips 4
</details> <details><summary>Zero-shot Evaluation<p></summary>

We use the Kinetics-400 pre-trained model (e.g., ViT-L/14 with 8 frames) to perform cross-dataset zero-shot evaluation, i.e., UCF101, HMDB51, ActivityNet, Kinetics-600.

# On ActivityNet: reporting the half-classes and full-classes results
# Half-classes: 86.18 Β± 1.05, Full-classes: 80.04
sh scripts/run_test_zeroshot.sh  configs/anet/anet_zero_shot.yaml exps/k400/ViT-L/14/8f/k400-vit-l-14-f8.pt

# On UCF101: reporting the half-classes and full-classes results
# Half-classes: 86.63 Β± 3.4, Full-classes: 80.83
sh scripts/run_test_zeroshot.sh  configs/ucf101/ucf_zero_shot.yaml exps/k400/ViT-L/14/8f/k400-vit-l-14-f8.pt

# On HMDB51: reporting the half-classes and full-classes results
# Half-classes: 61.37 Β± 3.68, Full-classes: 52.75
sh scripts/run_test_zeroshot.sh  configs/hmdb51/hmdb_zero_shot.yaml exps/k400/ViT-L/14/8f/k400-vit-l-14-f8.pt

# On Kinetics-600: manually calculating the mean accuracy with standard deviation of three splits.
# Split1: 70.14, Split2: 68.31, Split3: 67.15
# Average: 68.53 Β± 1.23
sh scripts/run_test.sh  configs/k600/k600_zero_shot_split1.yaml exps/k400/ViT-L/14/8f/k400-vit-l-14-f8.pt
sh scripts/run_test.sh  configs/k600/k600_zero_shot_split2.yaml exps/k400/ViT-L/14/8f/k400-vit-l-14-f8.pt
sh scripts/run_test.sh  configs/k600/k600_zero_shot_split3.yaml exps/k400/ViT-L/14/8f/k400-vit-l-14-f8.pt
</details>

<a name="bibtex"></a>

πŸ“Œ BibTeX & Citation

If you use our code in your research or wish to refer to the baseline results, please use the following BibTeX entry😁.

@inproceedings{bike,
  title={Bidirectional Cross-Modal Knowledge Exploration for Video Recognition with Pre-trained Vision-Language Models},
  author={Wu, Wenhao and Wang, Xiaohan and Luo, Haipeng and Wang, Jingdong and Yang, Yi and Ouyang, Wanli},
  booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
  year={2023}
}

If you also find Text4Vis useful 😁, please cite the paper:

@article{text4vis,
  title={Revisiting Classifier: Transferring Vision-Language Models for Video Recognition},
  author={Wu, Wenhao and Sun, Zhun and Ouyang, Wanli},
  booktitle={Proceedings of AAAI Conference on Artificial Intelligence (AAAI)},
  year={2023}
}

<a name="acknowledgment"></a>

πŸŽ—οΈ Acknowledgement

This repository is built based on Text4Vis, ActionCLIP, and CLIP. Sincere thanks to their wonderful works.

πŸ‘« Contact

For any question, please file an issue.