Spaces:
Running
Running
Update src/rmvpe.py
Browse files12345678239 unmodified lines2482492502512522532543 unmodified lines258259260261262263120 unmodified lines3843853863873883893903914 unmodified lines396397398399400401402403404405406407408409import numpy as npimport torchimport torch.nn as nnimport torch.nn.functional as Ffrom librosa.filters import melclass BiGRU(nn.Module):239 unmodified lines)else:self.fc = nn.Sequential(nn.Linear(3 * N_MELS, N_CLASS), nn.Dropout(0.25), nn.Sigmoid())def forward(self, mel):3 unmodified linesreturn xclass MelSpectrogram(torch.nn.Module):def __init__(self,120 unmodified linesdef to_local_average_cents(self, salience, thred=0.05):# t0 = ttime()center = np.argmax(salience, axis=1) # 帧长#indexsalience = np.pad(salience, ((0, 0), (4, 4))) # 帧长,368# t1 = ttime()center += 4todo_salience = []4 unmodified linestodo_salience.append(salience[:, starts[idx] : ends[idx]][idx])todo_cents_mapping.append(self.cents_mapping[starts[idx] : ends[idx]])# t2 = ttime()todo_salience = np.array(todo_salience) # 帧长,9todo_cents_mapping = np.array(todo_cents_mapping) # 帧长,9product_sum = np.sum(todo_salience * todo_cents_mapping, 1)weight_sum = np.sum(todo_salience, 1) # 帧长devided = product_sum / weight_sum # 帧长# t3 = ttime()maxx = np.max(salience, axis=1) # 帧长devided[maxx <= thred] = 0# t4 = ttime()# print("decode:%s\t%s\t%s\t%s" % (t1 - t0, t2 - t1, t3 - t2, t4 - t3))return devided1234567239 unmodified lines2472482492502512522533 unmodified lines257258259260261262263264265120 unmodified lines3863873883893903913923934 unmodified lines398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432import torch, numpy as npimport torch.nn as nnimport torch.nn.functional as Fclass BiGRU(nn.Module):239 unmodified lines)else:self.fc = nn.Sequential(nn.Linear(3 * nn.N_MELS, nn.N_CLASS), nn.Dropout(0.25), nn.Sigmoid())def forward(self, mel):3 unmodified linesreturn xfrom librosa.filters import melclass MelSpectrogram(torch.nn.Module):def __init__(self,120 unmodified linesdef to_local_average_cents(self, salience, thred=0.05):# t0 = ttime()center = np.argmax(salience, axis=1) # frame length#indexsalience = np.pad(salience, ((0, 0), (4, 4))) # frame length,368# t1 = ttime()center += 4todo_salience = []4 unmodified linestodo_salience.append(salience[:, starts[idx] : ends[idx]][idx])todo_cents_mapping.append(self.cents_mapping[starts[idx] : ends[idx]])# t2 = ttime()todo_salience = np.array(todo_salience) # frame length,9todo_cents_mapping = np.array(todo_cents_mapping) # frame length,9product_sum = np.sum(todo_salience * todo_cents_mapping, 1)weight_sum = np.sum(todo_salience, 1) # frame lengthdevided = product_sum / weight_sum # frame length# t3 = ttime()maxx = np.max(salience, axis=1) # frame lengthdevided[maxx <= thred] = 0# t4 = ttime()# print("decode:%s\t%s\t%s\t%s" % (t1 - t0, t2 - t1, t3 - t2, t4 - t3))return devided# if __name__ == '__main__':# audio, sampling_rate = sf.read("Quotations~1.wav") ### edit# if len(audio.shape) > 1:# audio = librosa.to_mono(audio.transpose(1, 0))# audio_bak = audio.copy()# if sampling_rate != 16000:# audio = librosa.resample(audio, orig_sr=sampling_rate, target_sr=16000)# model_path = "/bili-coeus/jupyter/jupyterhub-liujing04/vits_ch/test-RMVPE/weights/rmvpe_llc_half.pt"# thred = 0.03 # 0.01# device = 'cuda' if torch.cuda.is_available() else 'cpu'# rmvpe = RMVPE(model_path,is_half=False, device=device)# t0=ttime()# f0 = rmvpe.infer_from_audio(audio, thred=thred)# f0 = rmvpe.infer_from_audio(audio, thred=thred)# f0 = rmvpe.infer_from_audio(audio, thred=thred)# f0 = rmvpe.infer_from_audio(audio, thred=thred)# f0 = rmvpe.infer_from_audio(audio, thred=thred)# t1=ttime()# print(f0.shape,t1-t0)9
src/rmvpe.py+34-11