Home

Awesome

<div align="center"> <h2> ๐Ÿ”ฅใ€AAAI'2023, IJCV'2023ใ€‘Revisiting Classifier: Transferring Vision-Language Models for Video Recognition </h2>

Conference Journal

Wenhao Wu<sup>1,2</sup>, Zhun Sun<sup>2</sup>, Wanli Ouyang<sup>3,1</sup>

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

</div>

PWC PWC PWC PWC PWC PWC PWC

This is the official implementation of the AAAI paper Revisiting Classifier: Transferring Vision-Language Models for Video Recognition, and IJCV paper Transferring Vision-Language Models for Visual Recognition: A Classifier Perspective.

<details ><summary>๐Ÿ™‹ I also have other cross-modal video projects that may interest you โœจ. </summary><p>

Bidirectional Cross-Modal Knowledge Exploration for Video Recognition with Pre-trained Vision-Language Models<br> Wenhao Wu, Xiaohan Wang, Haipeng Luo, Jingdong Wang, Yi Yang, Wanli Ouyang <br> Conference 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>

๐Ÿ“ฃ Updates

๐ŸŒˆ Overview

In our Text4Vis, we revise the role of the linear classifier and replace the classifier with the different knowledge from pre-trained model. We utilize the well-pretrained language model to generate good semantic target for efficient transferring learning.

1
2

Content

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

๐Ÿ“• Prerequisites

The code is built with following libraries:

<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 detaied guide of data 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. Here is the format:

abseiling/-7kbO0v4hag_000107_000117 300 0
abseiling/-bwYZwnwb8E_000013_000023 300 0

(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. Example of annotation:

abseiling/-7kbO0v4hag_000107_000117.mp4 0
abseiling/-bwYZwnwb8E_000013_000023.mp4 0

Annotation

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

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

๐Ÿ“ฑ Model Zoo

Here we provide some off-the-shelf pre-trained checkpoints of our models in the following tables.

#Frame = #input_frame x #spatial crops x #temporal clips

Kinetics-400

Architecture#FrameTop-1 Acc.(%)checkpointTrain logconfig
ViT-B/328x3x480.0Githublogconfig
ViT-B/3216x3x480.5Githublogconfig
ViT-B/168x3x482.9Githublogconfig
ViT-B/1616x3x483.6Githublogconfig
ViT-L/14*8x3x486.4OneDrivelogconfig
ViT-L/14-3368x3x487.1OneDrivelogconfig
ViT-L/14-33632x3x187.8OneDrivelogconfig

Note: * indicates that this ViT-L model is used for the zero-shot evaluation on UCF, HMDB, ActivityNet and Kinetics-600.

ActivityNet

Architecture#FramemAP (%)checkpointTrain logconfig
ViT-L/1416x1x196.5OneDriveconfig
ViT-L/14-33616x1x196.9OneDrivelogconfig

UCF-101

Architecture#FrameTop-1 Acc. (%)checkpointTrain logconfig
ViT-L/1416x1x198.1OneDrivelogconfig
<!-- | ViT-L/14-336 | 16x1x1 | 98.2 | - | [log](exps/ucf101/ViT-L/14-336px/f16/log.txt) | [config](configs/ucf101/ucf_k400_finetune_336.yaml) | -->

HMDB-51

Architecture#FrameTop-1 Acc. (%)checkpointTrain logconfig
ViT-L/1416x1x181.3OneDrivelogconfig

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

๐Ÿš€ Training

This implementation supports Multi-GPU DistributedDataParallel training, which is faster and simpler than DataParallel used in ActionCLIP.

# For example, train the 8 Frames ViT-B/32.
sh scripts/run_train.sh  configs/k400/k400_train_rgb_vitb-32-f8.yaml
# For example, we train the 8 Frames ViT-L/14 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/k400_train_rgb_vitl-14-f8.yaml 0

# For second machine, --master_addr is still the ip of your first machine
sh scripts/run_train_multinodes.sh configs/k400/k400_train_rgb_vitl-14-f8.yaml 1
# You can refer to config/k400/k400_few_shot.yaml
data: 
    ...  # general configurations
    shot: 2  # i.e., 2-shot setting

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

โšก Testing

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

General/Few-shot Video Recognition

# Single view evaluation. e.g., ViT-B/32 8 Frames on Kinetics-400
sh scripts/run_test.sh  configs/k400/k400_train_rgb_vitb-32-f8.yaml exp/k400/ViT-B/32/f8/last_model.pt

# Multi-view evalition (4clipsx3crops). e.g., ViT-B/32 8 Frames on Kinetics-400
sh scripts/run_test.sh  configs/k400/k400_train_rgb_vitb-32-f8.yaml exp/k400/ViT-B/32/f8/last_model.pt --test_crops 3  --test_clips 4

Zero-shot Evaluation

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
sh scripts/run_test_zeroshot.sh  configs/anet/anet_zero_shot.yaml exp/k400/ViT-L/14/f8/last_model.pt

# On UCF101: reporting the half-classes and full-classes results
sh scripts/run_test_zeroshot.sh  configs/ucf101/ucf_zero_shot.yaml exp/k400/ViT-L/14/f8/last_model.pt

# On HMDB51: reporting the half-classes and full-classes results
sh scripts/run_test_zeroshot.sh  configs/hmdb51/hmdb_zero_shot.yaml exp/k400/ViT-L/14/f8/last_model.pt

# On Kinetics-600: manually calculating the mean accuracy with standard deviation of three splits.
sh scripts/run_test.sh  configs/k600/k600_zero_shot_split1.yaml exp/k400/ViT-L/14/f8/last_model.pt
sh scripts/run_test.sh  configs/k600/k600_zero_shot_split2.yaml exp/k400/ViT-L/14/f8/last_model.pt
sh scripts/run_test.sh  configs/k600/k600_zero_shot_split3.yaml exp/k400/ViT-L/14/f8/last_model.pt

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

๐Ÿ“Œ BibTeX & Citation

If you find this repository useful, please star๐ŸŒŸ this repo and cite๐Ÿ“‘ our paper:

@inproceedings{wu2023revisiting,
  title={Revisiting classifier: Transferring vision-language models for video recognition},
  author={Wu, Wenhao and Sun, Zhun and Ouyang, Wanli},
  booktitle={Proceedings of the AAAI Conference on Artificial Intelligence},
  volume={37},
  number={3},
  pages={2847--2855},
  year={2023}
}

@article{wu2023transferring,
  title={Transferring vision-language models for visual recognition: A classifier perspective},
  author={Wu, Wenhao and Sun, Zhun and Song, Yuxin and Wang, Jingdong and Ouyang, Wanli},
  journal={International Journal of Computer Vision},
  pages={1--18},
  year={2023},
  publisher={Springer}
}

If you also find BIKE useful, please cite the paper:

@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},
  year={2023}
}

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

๐ŸŽ—๏ธ Acknowledgement

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

๐Ÿ‘ซ Contact

For any question, please file an issue.