Giter Site home page Giter Site logo

lavish's Introduction

Vision Transformers are Parameter-Efficient Audio-Visual Learners

๐Ÿ“—Paper|| ๐Ÿ Project Page

License: MIT

This is the PyTorch implementation of our paper:

Vision Transformers are Parameter-Efficient Audio-Visual Learners

Yan-Bo Lin, Yi-Lin Sung, Jie Lei, Mohit Bansal, and Gedas Bertasius

In IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), 2023



Our Method

๐Ÿ“ Preparation

  • See each foloder for more detailed settings
  • Audio-Visual Event Localization: ./AVE
  • Audio-Visual Segmentation: ./AVS
  • Audio-Visual Question Answering: ./AVQA

๐ŸŽ“ Cite

If you use this code in your research, please cite:

@InProceedings{LAVISH_CVPR2023,
author = {Lin, Yan-Bo and Sung, Yi-Lin and Lei, Jie and Bansal, Mohit and Bertasius, Gedas},
title = {Vision Transformers are Parameter-Efficient Audio-Visual Learners},
booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
year = {2023}
}

๐Ÿ‘ Acknowledgments

Our code is based on AVSBench and MUSIC-AVQA

โœ Future works: model checkpoints

Tasks Checkpoints
AVE model
AVS model
AVQA model

lavish's People

Contributors

genjib avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

lavish's Issues

Can't get claimed accuracy (81.1%) with the provided configs?

After fixing few bugs I managed to reach ~79% accuracy only, I used the provided settings:
python3 main_trans.py --Adapter_downsample=8 --audio_folder=$PATH/raw_audio --batch_size=2 --early_stop=5 --epochs=50 --is_audio_adapter_p1=1 --is_audio_adapter_p2=1 --is_audio_adapter_p3=0 --is_before_layernorm=1 --is_bn=1 --is_fusion_before=1 --is_gate=1 --is_post_layernorm=1 --is_vit_ln=0 --lr=5e-05 --lr_mlp=4e-06 --mode=train --num_conv_group=2 --num_tokens=2 --num_workers=16 --video_folder=$PATH/video_frames --is_multimodal=1 --vis_encoder_type=swin

The code works on the validation set and the maximum accuracy is 78%, while the accuracy for the test set is 79%. Could you please provide the settings for reported results?

dataset shape not match in AVS

I try to run the code of avs, but the following error occurs:
XXXXXXXXXXXXXXXXX
File "../LAVISH/AVS/avs_scripts/avs_s4/model/PVT_AVSModel.py", line 492, in forward
x = self.swin.norm(x)
XXXXXXXXXXXXXXXXX
RuntimeError: Given normalized_shape=[1536], expected input with shape [*, 1536], but got input of size[5, 3, 192, 192]

Some bugs are hidden in the AVS repo

I tried to train the whole model in the AVS repo, but got some errors.
image

According to this problem, i guess there are some bugs hidden in the AVS repo, or more precisely, the two lines 513 and 518 should be exchanged, and final the x1 = multi_scale[0].view(multi_scale[0].size(0),64,64,-1) need to be commented.

x1 = multi_scale[0].view(multi_scale[0].size(0),64,64,-1)

x1 = self.x1_linear(x1)

My Solution

image

Can't get the accuracy of AVE reported in the paper with vit_base(75.3%)

Hi,
We used this config to train AVE task on a 3090, and we used the procesed data you provided, but the accuracy we got is 73.31

python3 /code/AVE/main_trans.py --Adapter_downsample=8 --batch_size=4 --early_stop=5 --epochs=50 --is_audio_adapter_p1=1 --is_audio_adapter_p2=1 --is_audio_adapter_p3=0 --is_before_layernorm=1 --is_bn=1 --is_fusion_before=1 --is_gate=1 --is_post_layernorm=1 --is_vit_ln=0 --lr=5e-06 --lr_mlp=4e-06 --mode=train --num_conv_group=2 --num_tokens=2 --num_workers=8 --is_multimodal=1 --vis_encoder_type=vit

And the

audio = audio[0]
doesn't used in forward_swin, this code will cause a "shape don't match" error.

Have you noticed that the AVQA model is very unstable when adjusting the lr and batch size?

When I tried to tune the batch size to 8 and tune the learning rates(adapter block lr and model lr) to 8 times the previous synchronously, the acc fall to 50%. I know it's not your fault, for I have trained the original baseline (Music-avqa), it also has such a problem.

I just want to discuss about that, did you meet the same problem when you tune the model? and how do you tackle it? I know the grid search for hyperparameters with lavish in avqa task is time consuming.

AVQA dimensional error

i have same error๏ผš
Traceback (most recent call last):
File "/LAVISH-main/AVQA/net_grd_avst/net_avst.py", line 318, in forward
audio = repeat(audio, 'b t len dim -> b t c len dim', c=3)
File "/root/anaconda3/lib/python3.9/site-packages/einops/einops.py", line 533, in repeat
return reduce(tensor, pattern, reduction='repeat', **axes_lengths)
File "/root/anaconda3/lib/python3.9/site-packages/einops/einops.py", line 420, in reduce
raise EinopsError(message + '\n {}'.format(e))
einops.EinopsError: Error while processing repeat-reduction pattern "b t len dim -> b t c len dim".
Input tensor shape: torch.Size([32, 10, 128]). Additional info: {'c': 3}.
Expected 4 dimensions, got 3

this my command:

python net_grd_avst/main_avst.py --mode train --audio_dir=/AVQA/MUSIC_AVQA/MUSIC-AVQA-main/data/vggish/ --video_res14x14_dir=/AVQA/MUSIC_AVQA/MUSIC-AVQA-main/data/

plz help me

For audio, you use both .wav format and .npy. Here is a dimensional error in the code.

File "/home/LAVisH/LAVISH-main/AVQA/net_grd_avst/net_avst.py", line 317, in forward
audio = repeat(audio, 'b t len dim -> b t c len dim', c=3)
File "/home/anaconda3/envs/lavish/lib/python3.8/site-packages/einops/einops.py", line 537, in repeat
return reduce(tensor, pattern, reduction='repeat', **axes_lengths)
File "/home/anaconda3/envs/lavish/lib/python3.8/site-packages/einops/einops.py", line 418, in reduce
raise EinopsError(message + '\n {}'.format(e))
einops.EinopsError: Error while processing repeat-reduction pattern "b t len dim -> b t c len dim".
Input tensor shape: torch.Size([1, 10, 128]). Additional info: {'c': 3}.
Expected 4 dimensions, got 3

The output of vision transformers models are Nans

Hello,
Thanks for the amazing work. I am trying your LAVISH setup for a different dataset for emotion recognition. I found that the output of the LAVISH model (tried all variants of vits ) returns Nan after a few layers. May I know whether I need to use different mean and variance for normalizing the audio and visual inputs. If so, can you share the scripts to compute the mean and variance for data normalization for my data.

How many gpu days does the training procedure of AVQA take?

Hello, I'm intrested in your pretty work and trying to reproduce the result. But I found that I have to spend nearly 5 gpu days to train for the AVQA task on 1 3090 gpu. Is this normal?
This is the recorded time during training:

feature Embed time:  0.0016405582427978516                                                                                                                
time for posi encode:  0.26480627059936523                                                                                                                
time for nega encode:  0.09544777870178223                                                                                                                
time for grounding:  0.009487152099609375                                                                                                                 
time for result:  0.0050661563873291016

It can be seen that encoding one audio and positive visual sample using swin transformer with adapter spend 0.2s. So it will take 2 gpu days just to encode the positive feature for 30 epochs.

erro for AVQA

LAVISH-main/AVQA/net_grd_avst/net_avst.py", line 270, in init
self.nce_av = InfoNCELoss(margin=opt.tmp_av)
NameError: name 'InfoNCELoss' is not defined

avsbench shape not match

I try to run the code of Lavish on avs, but the following error occurs:

Traceback (most recent call last):
File "/root/LAVISH/AVS/avs_scripts/avs_s4/train.py", line 247, in
output, visual_map_list, a_fea_list = model(imgs, audio_spec) # [bs*5, 1, 224, 224]
File "/root/miniconda3/envs/LAVISH_AVS/lib/python3.9/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "/root/miniconda3/envs/LAVISH_AVS/lib/python3.9/site-packages/torch/nn/parallel/data_parallel.py", line 159, in forward
return self.module(*inputs[0], **kwargs[0])
File "/root/miniconda3/envs/LAVISH_AVS/lib/python3.9/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "/root/LAVISH/AVS/avs_scripts/avs_s4/model/PVT_AVSModel.py", line 492, in forward
x = self.swin.norm(x)
File "/root/miniconda3/envs/LAVISH_AVS/lib/python3.9/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(input, **kwargs)
File "/root/miniconda3/envs/LAVISH_AVS/lib/python3.9/site-packages/torch/nn/modules/normalization.py", line 169, in forward
return F.layer_norm(
File "/root/miniconda3/envs/LAVISH_AVS/lib/python3.9/site-packages/torch/nn/functional.py", line 2094, in layer_norm
return torch.layer_norm(input, normalized_shape, weight, bias, eps,
RuntimeError: Given normalized_shape=[1536], expected input with shape [
, 1536], but got input of size[20, 3, 192, 192]

some question about VisualAdapter in AVS

Hello๏ผŒ
You added rep_token to the calclation of the VisualAdapter in AVS.
I print the max of value during this process as shown in the Fig.
I can't understand why the value changed from zero to non-zero value after softmax operation.
If it is zero, what is its effection to the whole model?
Thanks~
2
1

cannot get the claimed accuracy in audio-visual event localization.

I use the default config in this repo to train AVE task without any modification. But the accuracy obtained is not the same as the reported in the paper. I'm a bit confused about this. Swin-V2 Large is also taken as the visual and audio encoder, but the best precision I get is 78.8, while the paper is 81.1.

Training shell
python3 main_trans.py --Adapter_downsample=8 --audio_folder=data/AVE_audio --batch_size=2 --early_stop=5 --epochs=50 \ --is_audio_adapter_p1=1 --is_audio_adapter_p2=1 --is_audio_adapter_p3=0 --is_before_layernorm=1 --is_bn=1 --is_fusion_before=1 \ --is_gate=1 --is_post_layernorm=1 --is_vit_ln=0 --lr=5e-05 --lr_mlp=4e-06 --mode=train \ --num_conv_group=2 --num_tokens=2 --num_workers=16 --video_folder=data/AVE_video_frames \ --is_multimodal=1 --vis_encoder_type=swin --wandb=1

Comparision
image
image

Questions about CrossAttention

Hi, could you please explain the cross attention you used in the paper is frozen or newly added? Where I can find the corresponding implementation? Thank you very much.

Maybe the effect of adapter is not such crucial?

I have tried to delete the adapter in both AVE and AVQA task, without other config changed. And the performance only decreased for around 1~2%. If we unlock the layernorm in original swinv2, the gap will be further narrowed. But if I finetune all parameters (without adapter) in AVE, the performance decreased a lot, maybe the learning schedule needs to be adjusted simultaneously.

And there is an interesting phenomenon that if I delete the adapter, the model need more epochs to achieve the best performance, which indicated that the added trainable parameters can accelerate the training. Of course, it may also be caused by the need to adjust the learning rate.

About performance in AVQA

Hi, what set you used to report the performance of AVQA, validation set or testing set? It seems that you use the validation set in your script. Thank you very much.

Is this the true config?

In the readme file of AVQA task, you have provided the command to train the model.

"python3 net_grd_avst/main_avst.py --Adapter_downsample=8 --audio_dir=/data/yanbo/Dataset/AVQA/vggish --batch-size=1 --early_stop=5 --epochs=30 --is_before_layernorm=1 --is_bn=0 --is_gate=1 --is_multimodal=1 --is_post_layernorm=1 --is_vit_ln=1 --lr=8e-05 --lr_block=3e-06 --num_conv_group=4 --num_tokens=64 --num_workers=16 --video_res14x14_dir=/data/yanbo/Dataset/AVQA/ --wandb=1โ€œ

You only used 1 sample per batch? Or we could use the command in train.sh to reproduce the result?

Can't get th similar accuracy of AVE reported in the paper (81.1%)

Hi,
We used the same config in this repo to train AVE task on a 3090, but the accuracy we got is 78.96.

python3 main_trans.py --Adapter_downsample=8 --audio_folder=$PATH/raw_audio --batch_size=2 --early_stop=5 --epochs=50 --is_audio_adapter_p1=1 --is_audio_adapter_p2=1 --is_audio_adapter_p3=0 --is_before_layernorm=1 --is_bn=1 --is_fusion_before=1 --is_gate=1 --is_post_layernorm=1 --is_vit_ln=0 --lr=5e-05 --lr_mlp=4e-06 --mode=train --num_conv_group=2 --num_tokens=2 --num_workers=16 --video_folder=$PATH/video_frames --is_multimodal=1 --vis_encoder_type=swin

When we use the config in run_v2.sh, the accuracy is 80.05, which is different from those reported in the paper (81.1%). Is the result within the acceptable floating range?

Need few more details to debug the code for my task

Hello,
Thanks for sharing the code of your interesting work. I am trying to adapt your work for audio-visual speaker verification. In order to improve my results, I need few clarifications:

  1. May I know whether you have used mixup augmentation to get the results produced in the paper ?
  2. Can you please share the training logs or loss curves so that I can validate the pattern of my loss curves.

Thanks for your time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.