# Chromagrams from MATLAB
    chrom = sio.loadmat(fold + "/chrom.mat")['chroma']
    chromas = []
    names = []
    for i in range(0, chrom[0].shape[0]):
        try:
            names.append(float(chrom[0][i][0][0].replace('-', '.').replace('.mp3', '')))
            chromas.append(chrom[0][i][1][0][0][:, 0:514])
        except ValueError:
            y = chrom[0][i][1][0][0][:, 0:514]
    names_arr = np.asarray(names)
    x = np.argsort(names_arr)
    names = names_arr[x]
    chromas = [chromas[x1] for x1 in x]
    chrom_shape = chromas[0].shape
    lap_chrom = lap_pyramid(6, chrom_shape)
    yr = np.reshape(y, (1, chrom_shape[0], chrom_shape[1], 1))
    chrom_lap_temp, chrom_eucl_temp = [], []
    for c in chromas:
        cr = np.reshape(c, (1, chrom_shape[0], chrom_shape[1], 1))
        chrom_lap_temp.append(lap_chrom.compare(yr, cr))
        chrom_eucl_temp.append(np.sqrt(np.mean((y-c) ** 2)))

    for f in (glob.glob(fold + "*.wav")):
        y, sr = librosa.load(f, duration=12.0)
        c1s = librosa.core.stft(y=y)
        c1c = librosa.feature.chroma_stft(y=y, sr=sr, n_chroma=88)
        c1s = np.vstack((c1s.real, c1s.imag))
        stft_shape = c1s.shape
        c1sr = np.reshape(c1s, (1, stft_shape[0], stft_shape[1], 1))
        chrom_shape = c1c.shape
import matplotlib.pyplot as plt
import glob
from mutagen.mp3 import MP3
from pydub import AudioSegment
from pydub.utils import mediainfo


files = (glob.glob("./Audio Files/*.mp3"))

y, sr = librosa.load('nonoise.wav', duration=10.0) # bitrate = 706k
#c1 = librosa.feature.chroma_cqt(y=y, sr=sr, n_chroma=88)[:, 0:430]
c1 = librosa.core.stft(y=y)
chrom_shape = c1.shape
c1r = np.reshape(c1, (1, chrom_shape[0], chrom_shape[1], 1))

lap = lap_pyramid(6, chrom_shape)

scores = []
eucl = []
bitrates = []



for f in tqdm(files):
    y2, sr2 = librosa.load(f, duration=10.0)
    m = MP3(f)
    bitrates.append(m.info.bitrate/1000)
    #chrom = librosa.feature.chroma_cqt(y=y2, sr=sr2, n_chroma=88)[:, 0:430]
    chrom = librosa.core.stft(y=y2)
    chromr = np.reshape(chrom, (1, chrom_shape[0], chrom_shape[1], 1))
    scores.append(lap.compare(c1r, chromr))
Beispiel #3
0
from scipy.spatial import distance
from tqdm import tqdm

y, sr = librosa.load(librosa.util.example_audio_file(), duration=10.0)
sigmas = np.linspace(0.01, 0.1, 10)
c1 = librosa.feature.chroma_cqt(y=y, sr=sr, n_chroma=88)[:, 0:430]
chrom_shape = c1.shape
c1r = np.reshape(c1, (1, chrom_shape[0], chrom_shape[1], 1))

kern = [[0.0025, 0.0125, 0.0200, 0.0125, 0.0025],
        [0.0125, 0.0625, 0.1000, 0.0625, 0.0125],
        [0.0200, 0.1000, 0.1600, 0.1000, 0.0200],
        [0.0125, 0.0625, 0.1000, 0.0625, 0.0125],
        [0.0025, 0.0125, 0.0200, 0.0125, 0.0025]]
kern = np.reshape(kern, (5, 5, 1, 1))
lap = lap_pyramid(6, chrom_shape, kernel=kern)
scores = []
eucl = []
for sig in tqdm(sigmas):
    noise = np.random.normal(0, sig, y.shape[0])
    chrom = librosa.feature.chroma_cqt(y=(y + noise), sr=sr,
                                       n_chroma=88)[:, 0:430]
    chromr = np.reshape(chrom, (1, chrom_shape[0], chrom_shape[1], 1))
    scores.append(lap.compare(c1r, chromr))
    eucl.append(np.sqrt(np.mean((c1 - chrom)**2)))

plt.figure()
plt.subplot(2, 1, 1)
plt.scatter(sigmas, scores, marker='x')
plt.title('Normalised Laplacian Pyramid')
plt.xlabel('Additive Gaussian Noise standard deviation')
Beispiel #4
0
import numpy as np
from tqdm import tqdm
from lap_pyramid import *
from keras.layers import Input, Dense, Conv2D, MaxPooling2D, UpSampling2D
from keras.models import Model
from keras.datasets import mnist
import matplotlib.pyplot as plt
import tensorflow as tf

lap = lap_pyramid(6, [28, 28], loss=True)


def custom_loss(real, pred):
    s = lap.loss_function(real, pred)
    print(s)
    return s


input_img = Input(shape=(28, 28, 1))
x = Conv2D(16, (3, 3), activation='relu', padding='same')(input_img)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
encoded = MaxPooling2D((2, 2), padding='same')(x)

x = Conv2D(8, (3, 3), activation='relu', padding='same')(encoded)
x = UpSampling2D((2, 2))(x)
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
x = UpSampling2D((2, 2))(x)
x = Conv2D(16, (3, 3), activation='relu')(x)
Beispiel #5
0
            'Song': splt[-1],
            'Album': splt[-2],
            'Pyramid': pyr
        },
                       ignore_index=True)
    album = pd.Series(df['Album']).astype('category')
    album_number = album.cat.codes
    df['Album Number'] = album_number
    return df


if __name__ == "__main__":
    start_time = time.time()
    flac_path = '/Users/ah13558/Documents/flac/'
    base_y, base_sr = librosa.load(flac_path + "base.flac", duration=12.0)
    lap = lap_pyramid(6, [2050, 513])
    df = create_pyramid_dataframe(flac_path, lap)
    scores = distance.cdist(list(df['Pyramid']),
                            list(df['Pyramid']),
                            metric=calc_rmse)

    # Create graph
    colors = [set3[x] for x in list(df['Album Number'])]
    plot = figure(title="LAPD Songs",
                  x_range=(-1.1, 1.1),
                  y_range=(-1.1, 1.1),
                  plot_width=800,
                  plot_height=800)
    G = nx.from_numpy_matrix(scores)
    graph_renderer = from_networkx(G, nx.spring_layout)
    graph_renderer.node_renderer.data_source.add(colors, 'fillcolor')