Beispiel #1
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author     : Hongzhuo Liang
# E-mail     : [email protected]
# Description:
# Date       : 20/03/2019: 4:36 PM
# File Name  : generate_npy_list
from __future__ import print_function
import glob
import os
from audio_pouring.utils.utils import get_pouring_path
import numpy as np

if __name__ == "__main__":
    dataset_path = os.path.join(get_pouring_path(), "dataset")
    dir_list = os.listdir(dataset_path)
    for npy_dir in dir_list:
        full_path = os.path.join(dataset_path, npy_dir)
        if os.path.isdir(full_path):
            npy_names = glob.glob(os.path.join(full_path, "*.npy"))
            if len(npy_names) != 0:
                print("save npy list in {} to a npy file".format(npy_dir))
                np.save(full_path + ".npy", npy_names)

    # combine generated npy files as bottle 0:
    npy_train_list_names = glob.glob(
        os.path.join(dataset_path, "npy_train*.npy"))
    npy_test_list_names = glob.glob(os.path.join(dataset_path,
                                                 "npy_test*.npy"))
    bottle0_train = np.array([])
    bottle0_test = np.array([])
# File Name     : dataset.py
# Purpose       :
# Creation Date : 05-01-2019
# Author        : Shuang Li [sli[at]informatik[dot]uni-hamburg[dot]de]
# Author        : Hongzhuo Liang [liang[at]informatik[dot]uni-hamburg[dot]de]
from __future__ import division, print_function
import os
import torch.utils.data
import torch.nn as nn
import torchvision.transforms as trans
import numpy as np
import yaml
from audio_pouring.utils.utils import get_pouring_path

config_file = os.path.join(get_pouring_path(), "config/preprocess.yaml")
config = yaml.load(open(config_file, "r"))


def pitch_shift_spectrogram(spectrogram):
    """ Shift a spectrogram along the frequency axis in the spectral-domain at
    random
    """
    nb_cols = spectrogram.shape[0]
    max_shifts = nb_cols // 20  # around 5% shift
    nb_shifts = np.random.randint(-max_shifts, max_shifts)

    return np.roll(spectrogram, nb_shifts, axis=0)


class PouringDataset(torch.utils.data.Dataset):
import os
import sys
import pickle
import math
import yaml
import pylab
import matplotlib.pyplot as plt
import librosa.util
import librosa.display
from scipy.signal import butter, filtfilt
from scipy import interpolate
import multiprocessing as mp
from audio_pouring.utils.utils import weight2height, get_pouring_path
import seaborn as sns

pkg_path = get_pouring_path()
config_file = os.path.join(pkg_path, "config/preprocess.yaml")
config = yaml.load(open(config_file, "r"))
fixed_length = config["fixed_audio_length"]  # unit seconds
target_frequency = config["frequency"]
n_fft = config["n_fft"]
win_size = config["win_size"]
overlap = config["overlap"]
win_length = int(
    win_size * target_frequency)  # win length, how many samples in this window
assert win_length >= n_fft, "win_length should larger equal than n_fft"
hop_length = int(win_length * overlap)
max_audio = config["max_audio"]
bottle_id_list = config["bottle_id_list"]

same_length_mode = True  # random sample a fixed length of sample