pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html
cd apex
pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" ./
sh preinstall.sh
Model | Pretrained Ckpt | Finetuned Ckpt on MSRVTT-Retrieval | Finetuned Ckpt on MSRVTT-Caption |
---|---|---|---|
VALOR-B | VALOR-base | VALOR_base_msr_ret.pt | VALOR_base_msr_cap.pt |
VALOR-L | VALOR-large | VALOR_large_msr_ret.pt | VALOR_large_msr_cap.pt |
Put VALOR-base and VALOR-large under the output dir. (VALOR/output/VALOR-base, VALOR/output/VALOR-large)
VALOR is pretrained and tested on multiple vision-language, audio-language and audiovisual-language datasets. e.g. PRETRAIN: VALOR-1M, WebVid-2.5M, CC-3M (VALOR-base) TEST: VALOR-32K, MSRVTT, MSVD, DiDeMo, LSMDC, ActivityNet, VATEX, AudioCaps, ClothoV1, TGIF-Frame, MSCOCO, VQAV2... We here take MSRVTT as an example to show the data processing procedures, other datasets take a similar way.
The processed dataset path should be as follows:
├── datasets
│ ├── msrvtt
│ │ ├── raw_videos
│ │ │ ├── video0.mp4
│ │ │ └── video1.mp4
│ │ ├── frames_fps4
│ │ │ ├── video0
│ │ │ │ ├──img_0001.jpg
│ │ │ │ └──img_0002.jpg
│ │ │ └── video1
│ │ │ │ ├──img_0001.jpg
│ │ │ │ └──img_0002.jpg
│ │ ├── audio_22050hz
│ │ │ ├── video1.wav
│ │ │ └── video3.wav
│ │ ├── standardsplit_train_id.json
│ │ ├── standardsplit_test_id.json
│ │ ├── 1KAsplit_train_id.json
│ │ ├── 1KAsplit_test_id.json
│ │ ├── txt_mapper.json
│ │ ├── txt_mapper_1kAsplit_test.json
│ │ ├── txt_mapper_vqa.json
│ │ └── caption_annotation.json
We provide processed json files for most finetuneing datasets here, and you only need to download and extract raw videos of each dataset.
sh scripts/finetune_ret.sh $pretrain_path(output/VALOR_base)
sh scripts/finetune_cap.sh $pretrain_path(output/VALOR_base)
sh scripts/finetune_qa.sh $pretrain_path(output/VALOR_base)
The finetuning output path will be the subdir of $pretrain_path
For example, the cmd for finetuning retrieval model in scripts/finetune_ret.sh is as follows:
CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python -m torch.distributed.launch --nproc_per_node=8 --master_port 32711 ./train.py \
--pretrain_dir $basedir \
--config ./config/fast-retrieval-msrvtt.json \
--output_dir $basedir'/ret-msrvtt-lr2e-5-bs64-epoch5' \
--learning_rate 2e-5 \
--train_video_sample_num 4 \
--test_video_sample_num 8 \
--save_best true \
if you want to test model, just add following two rows to the cmd:
--zero_shot \
--checkpoint $checkpoint_save_path(.pt)
sh scripts/pretrain.sh
For QA task
python inference.py --video_path $VIDEOPATH --task 'qa%tva' --model_dir $MODELDIR --question 'what is in the video'
For caption task
python inference.py --video_path $VIDEOPATH --task 'cap%tva' --model_dir $MODELDIR
VALOR's framework is easy to expand new tasks/datasets. what you need to do is
In development stage, you can simply use cmd to overwrite config file. The most important args are : --learning_rate --train_batch_size --train_video_sample_num --test_video_sample_num --train_audio_sample_num --test_audio_sample_num --video_resolution --train_epoch --train_task --test_task
To control task and used modality group, you can rewrite train_task by 'task%modality_group1%modality_group2' For example: finetuning text-to-audio retrieval 'ret%ta' finetuning text-to-video retrieval 'ret%tv' or 'ret%tva'
Other settings --fp16 (default: True) --checkpointing (default: False)
If you find this code useful for your research, please consider citing:
@article{chen2023valor,
title={VALOR: Vision-Audio-Language Omni-Perception Pretraining Model and Dataset},
author={Chen, Sihan and He, Xingjian and Guo, Longteng and Zhu, Xinxin and Wang, Weining and Tang, Jinhui and Liu, Jing},
journal={arXiv preprint arXiv:2304.08345},
year={2023}
}
MIT -->