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

fix Mel and humpback

parent 27d0829a
No related branches found
No related tags found
No related merge requests found
import hdbscan
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from sklearn import metrics
species = np.loadtxt('good_species.txt', dtype=str)
frontends = ['16_pcenMel128', '16_logMel128', '16_logSTFT', '16_Mel128', '8_pcen64', '32_pcenMel128']
plt.figure()
for specie in species:
df = pd.read_csv(f'{specie}/{specie}.csv')
for i, frontend in enumerate(frontends):
print(specie, frontend)
dic = np.load(f'{specie}/encodings_{specie}_{frontend}_sparrow_encoder_decod2_BN_nomaxPool.npy', allow_pickle=True).item()
idxs, encodings, X = dic['idxs'], dic['encodings'], dic['umap']
clusters = hdbscan.HDBSCAN(min_cluster_size=5, min_samples=None, cluster_selection_epsilon=0.0, core_dist_n_jobs=-1, cluster_selection_method='best').fit_predict(X)
df.loc[idxs, 'cluster'] = clusters.astype(int)
mask = ~df.loc[idxs].label.isna()
clusters, labels = clusters[mask], df.loc[idxs[mask]].label
plt.scatter(metrics.normalized_mutual_info_score(labels, clusters), i, label=specie)
df.drop('cluster', inplace=True)
plt.ytick_labels(range(len(frontends)), frontends)
plt.ylabel('archi')
plt.xlabel('NMI with expert labels')
plt.grid()
plt.legend()
plt.savefig('NMIs_hdbscan.pdf')
\ No newline at end of file
import hdbscan
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from sklearn import metrics, cluster
from scipy.stats import linregress
species = np.loadtxt('good_species.txt', dtype=str)
frontends = ['16_pcenMel128', '16_logMel128', '16_logSTFT', '16_Mel128', '8_pcen64', '32_pcenMel128']
plt.figure()
for specie in species:
df = pd.read_csv(f'{specie}/{specie}.csv')
for i, frontend in enumerate(frontends):
print(specie, frontend)
dic = np.load(f'{specie}/encodings_{specie}_{frontend}_sparrow_encoder_decod2_BN_nomaxPool.npy', allow_pickle=True).item()
idxs, encodings, X = dic['idxs'], dic['encodings'], dic['umap']
ks = (5*1.2**np.arange(20)).astype(int)
distorsions = [cluster.KMeans(n_clusters=k).fit(encodings).inertia_ for k in ks]
errors = [linregress(ks[:i], distorsions[:i]).stderr + linregress(ks[i+1:], distorsions[i+1:]).stderr for i in range(2, len(ks)-2)]
k = ks[np.argmin(errors)]
clusters = cluster.KMeans(n_clusters=k).fit_predict(encodings)
df.loc[idxs, 'cluster'] = clusters.astype(int)
mask = ~df.loc[idxs].label.isna()
clusters, labels = clusters[mask], df.loc[idxs[mask]].label
plt.scatter(metrics.normalized_mutual_info_score(labels, clusters), i, label=specie)
df.drop('cluster', inplace=True)
plt.ytick_labels(range(len(frontends)), frontends)
plt.ylabel('archi')
plt.xlabel('NMI with expert labels')
plt.grid()
plt.legend()
plt.savefig('NMIs_kmeans.pdf')
\ No newline at end of file
from tqdm import tqdm
from soundsig.sound import Biosound
import soundfile as sf
import argparse
import pandas as pd
import models
parser = argparse.ArgumentParser()
parser.add_argument("specie", type=str)
args = parser.parse_args()
df = pd.read_csv(f'{args.specie}/{args.specie}.csv')
def norm(arr):
return (arr - np.mean(arr) ) / np.std(arr)
meta = models.meta[args.specie]
for idx, row in tqdm(df.iterrows(), total=len(df)):
info = sf.info(self.audiopath+row.fn)
dur, fs = info.duration, info.samplerate
start = int(np.clip(row.pos - meta['sampleDur']/2, 0, max(0, dur - meta['sampleDur'])) * fs)
sig, fs = sf.read(self.audiopath+row.fn, start=start, stop=start + int(meta['sampleDur']*fs))
if sig.ndim == 2:
sig = sig[:,0]
if len(sig) < meta['sampleDur'] * fs:
sig = np.concatenate([sig, np.zeros(int(self.sampleDur * fs) - len(sig))])
sound = BioSound(soundWave=norm(sig), fs=fs)
sound.spectroCalc(max_freq=meta['sr']//2)
sound.rms = myBioSound.sound.std()
sound.ampenv(cutoff_freq = 20, amp_sample_rate = 1000)
sound.spectrum(f_high=10000)
sound.fundest(maxFund = 1500, minFund = 300, lowFc = 200, highFc = 6000,
minSaliency = 0.5, debugFig = 0,
minFormantFreq = 500, maxFormantBW = 500, windowFormant = 0.1,
method='Stack')
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment