from poi_detector.src.dataset.e_create_dataset.Classes.output_handler import OutputDatasetHandler from poi_detector.src.dataset.e_create_dataset.Classes.data_balancer import DatasetBalancer from os.path import join as os_path_join base_dir = 'D:/Documents/Thesis/Project Skaterbot/Datasets/Library/' transform_type = 'spectrogram' time_size = 1000 freq_size = 20 window_size = 100 dataset_dir = os_path_join(base_dir, str(window_size)) input_handler = InputDatasetHandler(transform_type, window_size) output_handler = OutputDatasetHandler(window_size) balancer = DatasetBalancer() names, pois_lists = get_data_from_csv(relative_locator_csv_path) n_samples = names.shape[0] i = 0 for name, pois_list in zip(names, pois_lists): i += 1 try: print('Trying', i, 'out of', n_samples, '.') """ CREATE SPECTROGRAM """ spectrogram = input_handler.calculate_input(name, 'spectrogram', 512) balancer.save_input(dataset_dir, name + 'spectrogram', spectrogram) """ CREATE MEL-SPECTROGRAM """ melspectrogram = input_handler.calculate_input(name, 'melspectrogram', 256) balancer.save_input(dataset_dir, name + 'melspectrogram', melspectrogram)
base_dir = 'D:/Documents/Thesis/Project Skaterbot/Datasets/Library/' transform_type = 'cqt' freq_size = 512 window_size = 10 dataset_dir = os_path_join(base_dir, 'window_size_' + str(window_size)) data_dir = os_path_join(dataset_dir, 'data') try: os_mkdir(data_dir) except FileExistsError: pass input_handler = InputDatasetHandler(transform_type, window_size) names, pois_lists = get_data_from_csv(preciser_csv_path) sample_name = names[randint(0, names.shape[0])] try: print('Trying:', sample_name) """ CREATE CQT """ audio_data, sr = librosa.load(ospathjoin(wav_dir, sample_name), sr=44100) spectrogram = Transform.get_bad_spectrogram(audio_data, sr, freq_size, window_size) spectrogram = np.flip(spectrogram, axis=0) spec_dir = 'D:\Documents\Thesis\THESIS CHAPTERS\Chapter 2 - AUDIO AND TRANSFORMS' spec_path = ospathjoin(spec_dir, sample_name) skimage.io.imsave(spec_path + '_bad.jpg', spectrogram[:, 1000: 1512])
from __future__ import absolute_import, division, print_function, unicode_literals #from ..basic_classes.constants import wav_dir, preciser_csv_path, mels_dir from poi_detector.src.basic_classes.constants import wav_dir, preciser_csv_path, mels_dir from poi_detector.src.basic_classes.helper import get_data_from_csv from poi_detector.src.basic_classes.transforms import calculate_transform import numpy as np import librosa import pickle """ Get Input-names and Output-Points of Interest """ # the last csv that is used has all songs shuffled. No need to process input names. input_names, output_pois = get_data_from_csv(preciser_csv_path) n_samples = input_names.shape[0] transform_dir = mels_dir failed = [] min_val = 1000000000000000000000000 max_val = -100000000000000000000000 for i in range(n_samples): sample_name = input_names[i] output_sample = output_pois[i] print(sample_name) try: wav, sr = librosa.load(wav_dir + sample_name, mono=True, sr=44100) transformed_x = calculate_transform(wav, sr, 'melspectrogram', 512) print(transformed_x.shape) print(min_val, max_val) trans_max = np.amax(transformed_x) if trans_max > max_val: max_val = trans_max