Views
No views yet
1import torch
2from transformers import AutoModel, PreTrainedTokenizerFast
3import torchaudio
4
5
6device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
7
8model = AutoModel.from_pretrained(
9 "wsntxxn/cnn14rnn-tempgru-audiocaps-captioning",
10 trust_remote_code=True
11).to(device)
12tokenizer = PreTrainedTokenizerFast.from_pretrained(
13 "wsntxxn/audiocaps-simple-tokenizer"
14)
15
16wav, sr = torchaudio.load("/path/to/file.wav")
17wav = torchaudio.functional.resample(wav, sr, model.config.sample_rate)
18if wav.size(0) > 1:
19 wav = wav.mean(0).unsqueeze(0)
20
21with torch.no_grad():
22 word_idxs = model(
23 audio=wav,
24 audio_length=[wav.size(1)],
25 )
26
27caption = tokenizer.decode(word_idxs[0], skip_special_tokens=True)
28print(caption)1with torch.no_grad():
2 word_idxs = model(
3 audio=wav,
4 audio_length=[wav.size(1)],
5 temporal_tag=[2], # desribe "sequential" if there are sequential events, otherwise use the most complex relationship
6 )| Temporal Tag | Definition |
|---|---|
| 0 | Only 1 Event |
| 1 | Simultaneous Events |
| 2 | Sequential Events |
| 3 | More Complex Events |
1@inproceedings{xie2023enhance,
2 author = {Zeyu Xie and Xuenan Xu and Mengyue Wu and Kai Yu},
3 title = {Enhance Temporal Relations in Audio Captioning with Sound Event Detection},
4 year = 2023,
5 booktitle = {Proc. INTERSPEECH},
6 pages = {4179--4183},
7}