From ebdb895b4be80cd60f73363c331879a7273c0b62 Mon Sep 17 00:00:00 2001 From: Benjamin Elizalde <26778834+bmartin1@users.noreply.github.com> Date: Sat, 12 Nov 2022 10:47:39 -0800 Subject: [PATCH] Delete dataset_inference.py --- dataset_inference.py | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 dataset_inference.py diff --git a/dataset_inference.py b/dataset_inference.py deleted file mode 100644 index 03b7567..0000000 --- a/dataset_inference.py +++ /dev/null @@ -1,32 +0,0 @@ -from CLAP_API import CLAP -from esc50_dataset import ESC50 -import torch.nn.functional as F -import numpy as np -from tqdm import tqdm -from sklearn.metrics import accuracy_score - -# Load CLAP -weights_path = 'C:\\Users\\sdeshmukh\\Desktop\\CLAP_package\\model\\new\\best.pth' # Add weight path here -clap_model = CLAP(weights_path, use_cuda=False) - -# Load dataset -dataset = ESC50(root='data', download=True) -prompt = 'this is a sound of ' -Y = [prompt + x for x in dataset.classes] - -# Computing text embeddings -text_embeddings = clap_model.get_text_embeddings(Y) - -# Computing audio embeddings -y_preds, y_labels = [], [] -for i in tqdm(range(len(dataset))): - x, _, one_hot_target = dataset.__getitem__(i) - audio_embeddings = clap_model.get_audio_embeddings([x], resample=True) - similarity = clap_model.compute_similarity(audio_embeddings, text_embeddings) - y_pred = F.softmax(similarity.detach().cpu(), dim=1).numpy() - y_preds.append(y_pred) - y_labels.append(one_hot_target.detach().cpu().numpy()) - -y_labels, y_preds = np.concatenate(y_labels, axis=0), np.concatenate(y_preds, axis=0) -acc = accuracy_score(np.argmax(y_labels, axis=1), np.argmax(y_preds, axis=1)) -print('ESC50 Accuracy {}'.format(acc)) \ No newline at end of file