From 386e9f830ba666258ed617ab08877dc8b4a63c86 Mon Sep 17 00:00:00 2001 From: "Knut(Ke) Chen" Date: Mon, 10 Apr 2023 16:42:05 -0700 Subject: [PATCH] Update README.md --- README.md | 112 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 72 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 3d171f0..7347fc6 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,39 @@ # CLAP - -Contrastive Language-Audio Pretraining, known as CLAP. Referring to the CLIP (Contrastive Language-Image Pretraining) architecture, similarly, the CLAP architecture is as follows.

- The Contrastive Language-Audio Pretraining Model Architecture + The Contrastive Language-Audio Pretraining Model Architecture

+

+ + + +

+ +### This repository provides representations of audios and texts via Contrastive Language-Audio Pretraining (CLAP) +With CLAP, you can extract a latent representation of any given audio and text for your own model, or for different downstream tasks. +All codes are comming officially with the following paper, accepted by IEEE International Conference on Acoustics, Speech and Signal Processing, ICASSP 2023: + - [Large-Scale Contrastive Language-Audio Pretraining with Feature Fusion and Keyword-to-Caption Augmentation](https://arxiv.org/abs/2211.06687) -The repository contains code for the following paper, accepted by IEEE International Conference on Acoustics, Speech and Signal Processing, ICASSP 2023: - - [Large-scale Contrastive Language-Audio Pretraining with Feature Fusion and Keyword-to-Caption Augmentation](https://arxiv.org/abs/2211.06687) +**New Update: we release new CLAP pretrained checkpoints pretrained on music and speech data collecstions from [our dataset collection repo](https://github.com/LAION-AI/audio-dataset).** ## About this project This project is a project in [LAION](https://laion.ai/) that aims at learning better audio understanding and getting more audio data. This is an opensource project. We adopt the codebase of [open_clip](https://github.com/mlfoundations/open_clip) for this project. -The major opensource contributers of this project are (in equal contribution): Yusong Wu, Tianyu Zhang, Ke Chen. many thanks to @cfoster0 for allowing us to use his repo name. +## Architecture +Contrastive Language-Audio Pretraining, known as CLAP. Referring to the CLIP (Contrastive Language-Image Pretraining) architecture, the CLAP architecture is as follows. +

+ The Contrastive Language-Audio Pretraining Model Architecture +

+ ## Quick Start -We provide the library for our CLAP model: +We provide the PyPI library for our CLAP model: ```bash -pip install laion_clap +pip install laion-clap ``` Then you can follow the below usage or refer to [unit_test.py](https://github.com/LAION-AI/CLAP/blob/laion_clap_pip/src/laion_clap/unit_test.py). @@ -44,19 +56,19 @@ def float32_to_int16(x): return (x * 32767.).astype(np.int16) model = laion_clap.CLAP_Module(enable_fusion=False) -model.load_ckpt() +model.load_ckpt() # download the default pretrained checkpoint. # Directly get audio embeddings from audio files audio_file = [ - '/home/la/kechen/Research/KE_CLAP/ckpt/test_clap_short.wav', - '/home/la/kechen/Research/KE_CLAP/ckpt/test_clap_long.wav' + '/home/data/test_clap_short.wav', + '/home/data/test_clap_long.wav' ] audio_embed = model.get_audio_embedding_from_filelist(x = audio_file, use_tensor=False) print(audio_embed[:,-20:]) print(audio_embed.shape) # Get audio embeddings from audio data -audio_data, _ = librosa.load('/home/la/kechen/Research/KE_CLAP/ckpt/test_clap_short.wav', sr=48000) # sample rate should be 48000 +audio_data, _ = librosa.load('/home/data/test_clap_short.wav', sr=48000) # sample rate should be 48000 audio_data = audio_data.reshape(1, -1) # Make it (1,T) or (N,T) audio_embed = model.get_audio_embedding_from_data(x = audio_data, use_tensor=False) print(audio_embed[:,-20:]) @@ -64,15 +76,15 @@ print(audio_embed.shape) # Directly get audio embeddings from audio files, but return torch tensor audio_file = [ - '/home/la/kechen/Research/KE_CLAP/ckpt/test_clap_short.wav', - '/home/la/kechen/Research/KE_CLAP/ckpt/test_clap_long.wav' + '/home/data/test_clap_short.wav', + '/home/data/test_clap_long.wav' ] audio_embed = model.get_audio_embedding_from_filelist(x = audio_file, use_tensor=True) print(audio_embed[:,-20:]) print(audio_embed.shape) # Get audio embeddings from audio data -audio_data, _ = librosa.load('/home/la/kechen/Research/KE_CLAP/ckpt/test_clap_short.wav', sr=48000) # sample rate should be 48000 +audio_data, _ = librosa.load('/home/data/test_clap_short.wav', sr=48000) # sample rate should be 48000 audio_data = audio_data.reshape(1, -1) # Make it (1,T) or (N,T) audio_data = torch.from_numpy(int16_to_float32(float32_to_int16(audio_data))).float() # quantize before send it in to the model audio_embed = model.get_audio_embedding_from_data(x = audio_data, use_tensor=True) @@ -93,6 +105,51 @@ print(text_embed.shape) ``` +## Pretrained Models +The pretrained checkpoints can be found in [here](https://huggingface.co/lukewys/laion_clap/tree/main). +Please refer to the previous section for how to load and run the checkpoints. +For the PyPI library, [630k-audioset-best.pt](https://huggingface.co/lukewys/laion_clap/blob/main/630k-audioset-best.pt) and [630k-audioset-fusion-best.pt](https://huggingface.co/lukewys/laion_clap/blob/main/630k-audioset-fusion-best.pt) are our default models (non-fusion and fusion) + +We further provide below pretrained models according to your usages: + +* For general audio less than 10-sec: [630k-audioset-best.pt](https://huggingface.co/lukewys/laion_clap/blob/main/630k-audioset-best.pt) or [630k-best.pt](https://huggingface.co/lukewys/laion_clap/blob/main/630k-best.pt) +* For general audio with variable-length: [630k-audioset-fusion-best.pt](https://huggingface.co/lukewys/laion_clap/blob/main/630k-audioset-fusion-best.pt) or [630k-fusion-best.pt](https://huggingface.co/lukewys/laion_clap/blob/main/630k-fusion-best.pt) +* For music: [music_audioset_epoch_15_esc_90.14.pt](https://huggingface.co/lukewys/laion_clap/blob/main/music_audioset_epoch_15_esc_90.14.pt) +* For music and speech: [music_speech_epoch_15_esc_89.25.pt](https://huggingface.co/lukewys/laion_clap/blob/main/) +* For speech, music and general audio: [music_speech_audioset_epoch_15_esc_89.98.pt](https://huggingface.co/lukewys/laion_clap/blob/main/music_speech_audioset_epoch_15_esc_89.98.pt) + +The checkpoints list here for each model setting is the one with the highest average mAP score in training. +The average mAP score is calculated by averaging 4 scores: A-->T mAP@10 on AudioCaps, and T-->A mAP@10 on AudioCaps, A-->T mAP@10 on Clotho, and T-->A mAP@10 on Clotho. + +To use above pretrained models, you need to load the ckpt by yourself, as: + +Update 2023.4.7: we have released 3 larger CLAP models trained on music, speech dataset in addition to LAION-Audio-630k. Here are descriptions of the model and their performance: + + - `music_speech_audioset_epoch_15_esc_89.98.pt`: trained on music + speech + Audioset + LAION-Audio-630k. The zeroshot ESC50 performance is 89.98%, the GTZAN performance is 73%. + - `music_audioset_epoch_15_esc_90.14.pt`: trained on music + Audioset + LAION-Audio-630k. The zeroshot ESC50 performance is 90.14%, the GTZAN performance is 64%. + - `music_speech_epoch_15_esc_89.25.pt`: trained on music + speech + LAION-Audio-630k. The zeroshot ESC50 performance is 89.25%, the GTZAN performance is 73%. + +The model uses a larger audio encoder. To load the model using the pip API: +```python +import laion_clap +model = laion_clap.CLAP_Module(enable_fusion=False, amodel= 'HTSAT-base') +model.load_ckpt('checkpoint_path/checkpoint_name.pt') +``` + +Please note that this is a temporary release for people who are working on larger-scale down-stream task. +We will release a more comprehensive version of the model with detailed experiments in the future. +Please take your own risk when using this model. + +* All the new checkpoints did not trained with fusion. The training dataset size for `music_speech_audioset_epoch_15_esc_89.98.pt` is around 4M samples. The zeroshot GTZAN score is evaluated using the prompt `This audio is a song.` + +We provide the CLAP's performance on audio classification tasks under the zero-shot setting or the supervised setting. More results can be found at our paper. +

+ Zero-shot Performance +

+ + + + ## Environment Installation If you want to check and reuse our model into your project instead of directly using the pip library, you need to install the same environment as we use, please run the following command: ```bash @@ -124,31 +181,6 @@ To train on local dataset, please change the `--remotedata` in training scripts ## Core Code Please refer to [main.py](https://github.com/LAION-AI/CLAP/blob/laion_clap_pip/src/laion_clap/training/main.py), [train.py](https://github.com/LAION-AI/CLAP/blob/laion_clap_pip/src/laion_clap/training/train.py), [data.py](https://github.com/LAION-AI/CLAP/blob/laion_clap_pip/src/laion_clap/training/data.py),and [model.py](https://github.com/LAION-AI/CLAP/blob/laion_clap_pip/src/laion_clap/clap_module/model.py) to quicly get familiar with our model. -## Pretrained Models -The pretrained checkpoints can be found in [here](https://huggingface.co/lukewys/laion_clap/tree/main). -Please refer to the previous section for how to load and run the checkpoints. - -The checkpoints list here for each model setting is the one with the highest average mAP score in training. -The average mAP score is calculated by averaging 4 scores: A-->T mAP@10 on AudioCaps, and T-->A mAP@10 on AudioCaps, A-->T mAP@10 on Clotho, and T-->A mAP@10 on Clotho. - -Update 2023.4.7: we have released 3 larger CLAP models trained on music, speech dataset in addition to LAION-Audio-630k. Here are descriptions of the model and their performance: - - - `music_speech_audioset_epoch_15_esc_89.98.pt`: trained on music + speech + Audioset + LAION-Audio-630k. The zeroshot ESC50 performance is 89.98%, the GTZAN performance is 73%. - - `music_audioset_epoch_15_esc_90.14.pt`: trained on music + Audioset + LAION-Audio-630k. The zeroshot ESC50 performance is 90.14%, the GTZAN performance is 64%. - - `music_speech_epoch_15_esc_89.25.pt`: trained on music + speech + LAION-Audio-630k. The zeroshot ESC50 performance is 89.25%, the GTZAN performance is 73%. - -The model uses a larger audio encoder. To load the model using the pip API: -```python -import laion_clap -model = laion_clap.CLAP_Module(enable_fusion=False, amodel= 'HTSAT-base') -model.load_ckpt('checkpoint_path/checkpoint_name.pt') -``` - -Please note that this is a temporary release for people who are working on larger-scale down-stream task. -We will release a more comprehensive version of the model with detailed experiments in the future. -Please take your own risk when using this model. - -* All the new checkpoints did not trained with fusion. The training dataset size for `music_speech_audioset_epoch_15_esc_89.98.pt` is around 4M samples. The zeroshot GTZAN score is evaluated using the prompt `This audio is a song.` ## Reproducibility An example of the preprocessed Clotho dataset in webdataset format can be download [here](https://drive.google.com/drive/folders/1mU9mBOe11jTFCrQRJQsUa4S-3TlNuYoI?usp=sharing) (by downloading, you will be agreeing the license described in the [Clotho dataset](https://zenodo.org/record/3490684#.Y9ALPeyZP1w)). The audio encoder pretrained with 48kHz AudioSet can be found [here](https://drive.google.com/drive/folders/1SMQyzJvc6DwJNuhQ_WI8tlCFL5HG2vk6?usp=sharing), where `HTSAT-fullset-imagenet-map=0.467.ckpt` is the checkpoint used to initalize our HTSAT audio encoder. You should get similar result by loading from the audio encoder checkpoint and training on same dataset.