Commit cf803d6a authored by Anthony Larcher's avatar Anthony Larcher
Browse files

debug data augmentation

parent 2e5aa5e9
......@@ -764,57 +764,63 @@ class FactorAnalyser:
tv_rank = self.F.shape[1]
# Set useful variables
with h5py.File(stat_server_filename, 'r') as fh: # open the first statserver to get size
_, sv_size = fh[prefix + 'stat1'].shape
nb_sessions = fh[prefix + "modelset"].shape[0]
iv_server = StatServer()
iv_server.modelset = fh.get(prefix + 'modelset')[()]
iv_server.segset = fh.get(prefix + 'segset')[()]
tmpstart = fh.get(prefix+"start")[()]
tmpstop = fh.get(prefix+"stop")[()]
iv_server.start = numpy.empty(fh[prefix+"start"].shape, '|O')
iv_server.stop = numpy.empty(fh[prefix+"stop"].shape, '|O')
iv_server.start[tmpstart != -1] = tmpstart[tmpstart != -1]
iv_server.stop[tmpstop != -1] = tmpstop[tmpstop != -1]
iv_server.stat0 = numpy.ones((nb_sessions, 1), dtype=STAT_TYPE)
with warnings.catch_warnings():
iv_server.stat1 = serialize(numpy.zeros((nb_sessions, tv_rank)))
iv_sigma = serialize(numpy.zeros((nb_sessions, tv_rank)))
nb_sessions = iv_server.modelset.shape[0]
batch_nb = int(numpy.floor(nb_sessions / float(batch_size) + 0.999))
batch_indices = numpy.array_split(numpy.arange(nb_sessions), batch_nb)
manager = multiprocessing.Manager()
q = manager.Queue()
pool = multiprocessing.Pool(num_thread + 2)
# put listener to work first
watcher = pool.apply_async(iv_collect, ((iv_server.stat1, iv_sigma), q))
# fire off workers
jobs = []
# Load data per batch to reduce the memory footprint
for batch_idx in batch_indices:
# Create list of argument for a process
arg = batch_idx, fh["stat0"][batch_idx, :], fh["stat1"][batch_idx, :], ubm, self.F
job = pool.apply_async(iv_extract_on_batch, (arg, q))
jobs.append(job)
fh = stat_server_filename
if isinstance(stat_server_filename, 'str'):
fh = h5py.File(stat_server_filename, 'r')
_, sv_size = fh[prefix + 'stat1'].shape
nb_sessions = fh[prefix + "modelset"].shape[0]
iv_server = StatServer()
iv_server.modelset = fh.get(prefix + 'modelset')[()]
iv_server.segset = fh.get(prefix + 'segset')[()]
tmpstart = fh.get(prefix+"start")[()]
tmpstop = fh.get(prefix+"stop")[()]
iv_server.start = numpy.empty(fh[prefix+"start"].shape, '|O')
iv_server.stop = numpy.empty(fh[prefix+"stop"].shape, '|O')
iv_server.start[tmpstart != -1] = tmpstart[tmpstart != -1]
iv_server.stop[tmpstop != -1] = tmpstop[tmpstop != -1]
iv_server.stat0 = numpy.ones((nb_sessions, 1), dtype=STAT_TYPE)
with warnings.catch_warnings():
iv_server.stat1 = serialize(numpy.zeros((nb_sessions, tv_rank)))
iv_sigma = serialize(numpy.zeros((nb_sessions, tv_rank)))
nb_sessions = iv_server.modelset.shape[0]
batch_nb = int(numpy.floor(nb_sessions / float(batch_size) + 0.999))
batch_indices = numpy.array_split(numpy.arange(nb_sessions), batch_nb)
manager = multiprocessing.Manager()
q = manager.Queue()
pool = multiprocessing.Pool(num_thread + 2)
# put listener to work first
watcher = pool.apply_async(iv_collect, ((iv_server.stat1, iv_sigma), q))
# fire off workers
jobs = []
# Load data per batch to reduce the memory footprint
for batch_idx in batch_indices:
# Create list of argument for a process
arg = batch_idx, fh["stat0"][batch_idx, :], fh["stat1"][batch_idx, :], ubm, self.F
job = pool.apply_async(iv_extract_on_batch, (arg, q))
jobs.append(job)
# collect results from the workers through the pool result queue
for job in jobs:
job.get()
# now we are done, kill the listener
q.put((None, None, None))
pool.close()
iv_server.stat1, iv_sigma = watcher.get()
# collect results from the workers through the pool result queue
for job in jobs:
job.get()
if isinstance(stat_server_filename, 'str'):
fh.close()
# now we are done, kill the listener
q.put((None, None, None))
pool.close()
iv_server.stat1, iv_sigma = watcher.get()
if uncertainty:
return iv_server, iv_sigma
else:
......
......@@ -411,7 +411,6 @@ class FeaturesServer(object):
:return: acoustic parameters and their vad labels
"""
# In case the name of the input file does not include the ID of the show
# (i.e., feature_filename_structure does not include {})
# self.audio_filename_structure is updated to use the input_feature_filename
......@@ -421,7 +420,6 @@ class FeaturesServer(object):
and self.previous_load is not None:
logging.debug('return previous load')
return self.previous_load
self.show = show
self.input_feature_filename = input_feature_filename
self.start_stop = (start, stop)
......@@ -487,7 +485,6 @@ class FeaturesServer(object):
feat, label = self.post_processing(feat, label, global_mean, global_std)
else:
feat, label = self.post_processing(feat, label)
return feat, label
def get_tandem_features(self, show, channel=0, label=None, start=None, stop=None):
......@@ -581,17 +578,15 @@ class FeaturesServer(object):
"""
while True:
next_task = input_queue.get()
if next_task is None:
# Poison pill means shutdown
output_queue.put(None)
input_queue.task_done()
break
output_queue.put(self.load(*next_task)[0])
input_queue.task_done()
#@profile
def stack_features_parallel(self, # fileList, numThread=1):
show_list,
......@@ -618,7 +613,6 @@ class FeaturesServer(object):
if stop_list is None:
stop_list = numpy.empty(len(show_list), dtype='|O')
#queue_in = Queue.Queue(maxsize=len(fileList)+numThread)
queue_in = multiprocessing.JoinableQueue(maxsize=len(show_list)+num_thread)
queue_out = []
......@@ -631,7 +625,7 @@ class FeaturesServer(object):
args=(queue_in, queue_out[i]))
jobs.append(p)
p.start()
# Submit tasks
for task in zip(show_list, channel_list, feature_filename_list,
label_list, start_list, stop_list):
......@@ -643,7 +637,6 @@ class FeaturesServer(object):
# Wait for all the tasks to finish
queue_in.join()
output = []
for q in queue_out:
while True:
......
......@@ -709,7 +709,6 @@ class Mixture(object):
n_frames = features.shape[0]
mu = features.mean(0)
cov = (features**2).mean(0)
#n_frames, mu, cov = mean_std_many(features_server, feature_list, in_context=False, num_thread=num_thread)
self.mu = mu[None]
self.invcov = 1./cov[None]
......@@ -757,9 +756,13 @@ class Mixture(object):
session_list = feature_list.rightids
else:
session_list = feature_list
self._init(features_server, session_list, start_list=start_list, stop_list=stop_list, num_thread=num_thread)
print("avant init")
init_session_list = session_list[:20]
if start_list is not None:
init_start_list = start_list[:20]
init_stop_list = stop_list[:20]
self._init(features_server, init_session_list, start_list=init_start_list, stop_list=init_stop_list, num_thread=num_thread)
print("fin init")
# for N iterations:
for it in iterations[:int(numpy.log2(distrib_nb))]:
# Save current model before spliting
......
......@@ -56,16 +56,6 @@ def crop(signal, duration):
return chunk
if 'AddReverb' in t:
_transform.append(AddReverb(ratio=dataset["train"]["augmentation"]["reverb_ratio"],
depth=dataset["train"]["augmentation"]["reverb_depth"],
width=dataset["train"]["augmentation"]["reverb_width"],
height=dataset["train"]["augmentation"]["reverb_height"],
absorption=dataset["train"]["augmentation"]["reverb_absorption"],
snr=dataset["train"]["augmentation"]["reverb_snr"]))
class AddNoise(object):
"""
......
......@@ -34,6 +34,7 @@ import pandas
import pickle
import random
import torch
import tqdm
import soundfile
import yaml
......@@ -49,8 +50,6 @@ from ..features_server import FeaturesServer
from scipy.fftpack.realtransforms import dct
from torchvision import transforms
from tqdm import tqdm
__license__ = "LGPL"
__author__ = "Anthony Larcher"
__copyright__ = "Copyright 2015-2020 Anthony Larcher"
......@@ -385,7 +384,7 @@ class SideSet(Dataset):
df_dict = dict(zip(df.columns, [[], [], [], [], [], [], []]))
# For each segment, get all possible segments with the current overlap
for idx in range(len(tmp_sessions)):
for idx in tqdm.trange(len(tmp_sessions)):
# Compute possible starts
possible_starts = numpy.arange(0,
int(self.sample_rate * (df.iloc[idx].duration - self.duration)),
......@@ -429,7 +428,7 @@ class SideSet(Dataset):
_transform.append(PreEmphasis())
if 'add_noise' in t:
self.add_noise[:int(self.len * self.transformation["noisy_file_ratio"])] = 1
self.add_noise[:int(self.len * self.transformation["noise_file_ratio"])] = 1
numpy.random.shuffle(self.add_noise)
_transform.append(AddNoise(noisy_file_ratio=self.transformation["noise_file_ratio"],
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment