Skip to content
Snippets Groups Projects
Commit 0bc68d81 authored by Paul Best's avatar Paul Best
Browse files

small stuff

parent 40fb1334
No related branches found
No related tags found
No related merge requests found
File added
......@@ -35,7 +35,7 @@ for specie in species if args.specie == 'all' else [args.specie]:
if FS*r.time < nfft//2 or FS*r.time > len(sig) - nfft//2 or (sig[int(FS*r.time) - nfft//2 : int(FS*r.time) + nfft//2] == 0).all():
continue
spec = get_spectrum(sig[int(FS*r.time) - nfft//2 : int(FS*r.time) + nfft//2])
spec = np.clip(spec-noise, 0, 10)
spec = np.clip(spec-noise, 1e-5, 10)
f0 = r.annot
df.loc[i, 'salience'] = sum(spec[Hz2bin(f0*2**(-1/12)):Hz2bin(f0*2**(1/12))+1]) / sum(spec[Hz2bin(f0*2**(-6/12)):Hz2bin(f0*2**(6/12))+1])
......
......@@ -31,7 +31,7 @@ for specie in species if args.specie=='all' else args.specie.split(' '):
confs['label'].extend(df.annot>0)
thrs = {}
for algo in list(algos):
if np.isnan(confs[algo]).all():
if np.isnan(confs[algo]).all() or len(confs[algo]) < len(confs['label']):
algos -= {algo}
continue
fpr, tpr, thr = skmetrics.roc_curve(np.array(confs['label'])[~np.isnan(confs[algo])], np.array(confs[algo])[~np.isnan(confs[algo])])
......@@ -49,7 +49,7 @@ for specie in species if args.specie=='all' else args.specie.split(' '):
return pd.DataFrame()
out = pd.DataFrame(columns=metrics)
for algo in algos:
if df[algo+'_f0'].isna().all():
if not algo+'_f0' in df.columns or df[algo+'_f0'].isna().all():
continue
out.loc[algo, ['Recall', 'False alarm']] = mir_eval.melody.voicing_measures(df.annot > 0, df[algo+'_conf'] > thrs[algo])
df[algo+'_f0'] = mir_eval.melody.hz2cents(df[algo+'_f0'])
......@@ -63,12 +63,14 @@ for specie in species if args.specie=='all' else args.specie.split(' '):
fig, ax = plt.subplots(ncols=3, figsize=(12, 4), sharex=True)
for i, algo in enumerate(algos):
if algo in df.index:
ax[0].violinplot(np.concatenate(df.loc[algo, 'diff_distrib']), positions=[i])
ax[1].violinplot(df.loc[algo, 'Pitch acc'], positions=[i])
ax[2].violinplot(df.loc[algo, 'Chroma acc'], positions=[i])
ax[0].set_yscale('log')
ax[0].set_title('Distrib of errors in cents')
ax[0].hlines(1200, 0, len(algos), linestyle='dashed', color='k')
ax[1].set_title('Distrib of pitch acc per vocs in % ')
ax[2].set_title('Distrib of chroma acc per vocs in % ')
plt.xticks(np.arange(len(algos)), algos, rotation=45)
......
No preview for this file type
......@@ -7,9 +7,9 @@ from metadata import species
np.seterr(divide = 'ignore')
fig, ax = plt.subplots(ncols=3, sharey=True, figsize=(10, 3.5))
ax[0].set_title('Frequency (Hz)')
ax[1].set_title('# Voiced time bins')
ax[2].set_title('Modulation rate (Hz/sec)')
ax[0].set_xlabel('Frequency (Hz)')
ax[1].set_xlabel('# Voiced time bins')
ax[2].set_xlabel('Modulation rate (Hz/sec)')
for i in range(3):
ax[i].set_xscale('log')
ax[i].grid()
......@@ -25,10 +25,15 @@ for i, specie in enumerate(species):
fdistrib.extend(f0s[mask2.astype(bool)])
tdistrib.append(mask2.sum())
moddistrib.extend(abs(np.diff(f0s[mask2.astype(bool)]))/dt)
ax[0].violinplot(fdistrib, positions=[i], vert=False)
ax[1].violinplot(tdistrib, positions=[i], vert=False)
ax[2].violinplot(moddistrib, positions=[i], vert=False)
p = ax[0].violinplot(fdistrib, points=1000, positions=[i], vert=False)
p['bodies'][-1].set_alpha(1)
p = ax[1].violinplot(tdistrib, points=1000, positions=[i], vert=False)
p['bodies'][-1].set_alpha(1)
p = ax[2].violinplot(moddistrib, points=1000, positions=[i], vert=False)
p['bodies'][-1].set_alpha(1)
ax[0].set_xticks(10**np.arange(1, 6))
plt.yticks(np.arange(len(species)), [s.replace('_',' ') for s in species])
plt.tight_layout()
plt.savefig('freq_distrib.pdf')
......@@ -3,7 +3,7 @@ import pandas as pd, numpy as np
from metadata import species
import argparse
algos = ['praat', 'tcrepe_ftsp', 'tcrepe_ftoth', 'basic', 'pesto', 'pesto_ft']
algos = ['praat', 'basic', 'pesto', 'pesto_ft', 'tcrepe_ftoth', 'tcrepe_ftsp']
metrics = ['Pitch acc', 'Chroma acc', 'Recall', 'Specificity']
parser = argparse.ArgumentParser()
......
......@@ -33,6 +33,7 @@ parser.add_argument('--quick', type=bool, help="Skip pyin and crepe to make thin
args = parser.parse_args()
algos = ['praat_f0','pyin_f0','crepe_f0','tcrepe_f0','tcrepe_ft_f0','tcrepe_ftsp_f0','tcrepe_ftoth_f0', 'basic_f0','pesto_f0', 'pesto_ft_f0']
quick_algos = ['praat_f0','tcrepe_f0','tcrepe_ft_f0','tcrepe_ftsp_f0','tcrepe_ftoth_f0', 'basic_f0','pesto_f0', 'pesto_ft_f0']
if args.overwrite:
print('Overwriting previous results')
......@@ -57,12 +58,9 @@ for specie in species if args.specie =='all' else args.specie.split(' '):
mask = ((out.time > annot.Time.min())&(out.time < annot.Time.max()))
out.loc[mask, 'annot'] = mir_eval.melody.resample_melody_series(annot.Time, annot.Freq, annot.Freq>0, out.loc[mask, 'time'], verbose=False)[0]
else:
out = pd.read_csv(f'{fn[:-4]}_preds.csv')
out = pd.read_csv(f'{fn[:-4]}_preds.csv').dropna(axis=1, how='all') # drop a column if all values are None
# check if everything has already been computed, and if yes skip the file
for algo in algos:
if algo in out.columns and out[algo].isna().all():
out.drop(algo, axis=1, inplace=True)
if pd.Series(algos).isin(out.columns).all():
if pd.Series(algos).isin(out.columns).all() or (args.quick and pd.Series(quick_algos).isin(out.columns).all()):
continue
sig, fs = librosa.load(fn, sr=FS)
......
File added
No preview for this file type
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment