Views
No views yet
1import torch
2from transformers import AutoModel
3
4audio_path = ['resources/1.wav', 'resources/2.wav'] # (B,)
5caption = ["A woman speaks, dishes clanking, food frying, and music plays", 'A power tool is heard with male speech.'] # (B,)
6phrases = ['Speech', 'Dog', 'Cat', 'Frying', 'Dishes', 'Music', 'Vacuum', 'Type', 'Power tool'] # (N,)
7
8
9device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
10
11model = AutoModel.from_pretrained("AndreasXi/FineLAP", trust_remote_code=True).to(device)
12model.eval()
13
14with torch.no_grad():
15 global_text_embeds = model.get_global_text_embeds(caption) # (B, d)
16 print(global_text_embeds.shape)
17
18 global_audio_embeds = model.get_global_audio_embeds(audio_path) # (B, d)
19 print(global_audio_embeds.shape)
20
21 dense_audio_embeds = model.get_dense_audio_embeds(audio_path) # (B, T, d)
22 print(dense_audio_embeds.shape)
23
24 clip_scores = model.get_clip_level_score(audio_path, caption) # (B, B)
25 print(clip_scores.shape)
26
27 frame_scores = model.get_frame_level_score(audio_path, phrases) # (B, N, T)
28 print(frame_scores.shape)
29
30 ## (Optional) Plot frame-level similarity, only supprt single audio file
31 model.plot_frame_level_score(audio_path[1], phrases, output_path="output/output_plot.png")