Skip to content
Snippets Groups Projects
Commit 8b658650 authored by Joseph Omar's avatar Joseph Omar
Browse files

Added files

parent 3729272f
No related branches found
No related tags found
No related merge requests found
Source diff could not be displayed: it is too large. Options to address this: view the blob.
This diff is collapsed.
import glob
import os
import pandas as pd
from seframework.utils.dnsmos import DNSMOS
import torch
import torch.utils
import torchaudio
torch.manual_seed(0)
device = torch.device("cuda:2")
dnsmos = DNSMOS(device=device, sample_rate=16000, cache_session=True)
def get_id(filename):
return int(os.path.basename(filename).split('_')[0])
noisy_filenames = glob.glob("vbd/training/noisy/*.wav")
noisy_filenames = sorted(noisy_filenames, key=lambda x: int(
os.path.basename(x).split('_')[0]))
batched_filenames = [tuple(noisy_filenames[i:i+4]) for i in range(0, len(noisy_filenames), 4)]
scores_ind = pd.DataFrame(columns=["batch", "raw_sig", "raw_bak", "raw_ovr", "sig", "bak", "ovr"])
scores_ind["batch"] = scores_ind["batch"].astype(int)
scores_batch = pd.DataFrame(columns=["raw_sig", "raw_bak", "raw_ovr", "sig", "bak", "ovr"])
for bidx, batch in enumerate(batched_filenames):
wavs = [torchaudio.load(filename)[0] for filename in batch]
wavs = [wav.to(device) for wav in wavs]
for fidx, filename in enumerate(batch):
wav = wavs[fidx]
scores_ind.loc[get_id(filename)] = dnsmos(wav)
scores_ind.loc[get_id(filename), "batch"] = bidx
biggest = max([b.shape[1] for b in wavs])
wavs = [torch.nn.functional.pad(wav, (0, biggest - wav.shape[1]), "constant", 0) for wav in wavs]
wavs = [torch.squeeze(wav, 0) for wav in wavs]
stack = torch.stack(wavs)
scores_batch.loc[bidx] = dnsmos(stack)
scores_ind.to_csv("scores_ind.csv")
scores_batch.to_csv("scores_batch.csv")
\ No newline at end of file
Source diff could not be displayed: it is too large. Options to address this: view the blob.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment