🚀 Huggingface在MuAViC數據集上對AV - HuBERT的實現
本倉庫包含了AV - HuBERT(Audio - Visual Hidden Unit BERT)模型的Huggingface實現,該模型專門在MuAViC(Multilingual Audio - Visual Corpus)數據集上進行了訓練和測試。AV - HuBERT是一個用於視聽語音識別的自監督模型,它利用音頻和視覺兩種模態來實現強大的性能,尤其在嘈雜環境中表現出色。
本倉庫的主要特性包括:
- 預訓練模型:可以獲取在MuAViC數據集上微調的預訓練AV - HuBERT模型。預訓練模型從MuAViC倉庫導出。
- 推理腳本:可藉助Huggingface的接口輕鬆構建推理管道。
- 數據預處理腳本:包括歸一化幀率、提取嘴唇和音頻等操作。
🚀 快速開始
推理代碼
git clone https://github.com/nguyenvulebinh/AV-HuBERT-S2S.git
cd AV-HuBERT-S2S
conda create -n avhuberts2s python=3.9
conda activate avhuberts2s
pip install -r requirements.txt
python run_example.py
from src.model.avhubert2text import AV2TextForConditionalGeneration
from src.dataset.load_data import load_feature
from transformers import Speech2TextTokenizer
import torch
if __name__ == "__main__":
AVAILABEL_LANGUAGES = ["ar", "de", "el", "en", "es", "fr", "it", "pt", "ru", "multilingual"]
language = "ru"
assert language in AVAILABEL_LANGUAGES, f"Language {language} is not available, please choose one of {AVAILABEL_LANGUAGES}"
model_name_or_path = f"nguyenvulebinh/AV-HuBERT-MuAViC-{language}"
model = AV2TextForConditionalGeneration.from_pretrained(model_name_or_path, cache_dir='./model-bin')
tokenizer = Speech2TextTokenizer.from_pretrained(model_name_or_path, cache_dir='./model-bin')
model = model.cuda().eval()
video_example = f"./example/video_processed/{language}_lip_movement.mp4"
audio_example = f"./example/video_processed/{language}_audio.wav"
if not os.path.exists(video_example) or not os.path.exists(audio_example):
print(f"WARNING: Example video and audio for {language} is not available english will be used instead")
video_example = f"./example/video_processed/en_lip_movement.mp4"
audio_example = f"./example/video_processed/en_audio.wav"
sample = load_feature(
video_example,
audio_example
)
audio_feats = sample['audio_source'].cuda()
video_feats = sample['video_source'].cuda()
attention_mask = torch.BoolTensor(audio_feats.size(0), audio_feats.size(-1)).fill_(False).cuda()
output = model.generate(
audio_feats,
attention_mask=attention_mask,
video=video_feats,
max_length=1024,
)
print(tokenizer.batch_decode(output, skip_special_tokens=True))
數據預處理腳本
mkdir model-bin
cd model-bin
wget https://huggingface.co/nguyenvulebinh/AV-HuBERT/resolve/main/20words_mean_face.npy .
wget https://huggingface.co/nguyenvulebinh/AV-HuBERT/resolve/main/shape_predictor_68_face_landmarks.dat .
cp raw_video.mp4 ./example/
python src/dataset/video_to_audio_lips.py
預訓練的AVSR模型
致謝
- AV - HuBERT:本倉庫的大部分代碼改編自原始的AV - HuBERT實現。
- MuAViC倉庫:我們也非常感謝MuAViC數據集和倉庫的創建者,他們為這個項目提供了預訓練模型。
📄 許可證
CC - BY - NC 4.0
引用
@article{anwar2023muavic,
title={MuAViC: A Multilingual Audio-Visual Corpus for Robust Speech Recognition and Robust Speech-to-Text Translation},
author={Anwar, Mohamed and Shi, Bowen and Goswami, Vedanuj and Hsu, Wei-Ning and Pino, Juan and Wang, Changhan},
journal={arXiv preprint arXiv:2303.00628},
year={2023}
}