Exemplo n.º 1
0
    def __init__(self, conf, evalconf, dataconf, rec_dir, numbatches, task):
        '''Reconstructor constructor
        Args:
            conf: the scorer configuration as a dictionary
            evalconf: the evaluator configuration as a ConfigParser
            dataconf: the database configuration
            rec_dir: the directory where the reconstructions are
            numbatches: the number of batches to process
        '''

        if evalconf.has_option(task, 'batch_size'):
            batch_size = int(evalconf.get(task, 'batch_size'))
        else:
            batch_size = int(evalconf.get('evaluator', 'batch_size'))
        self.tot_utt = batch_size * numbatches
        print batch_size, self.tot_utt

        self.rec_dir = rec_dir
        self.segment_lengths = evalconf.get('evaluator',
                                            'segment_length').split(' ')

        #get the original source signals reader
        org_src_name = conf['org_src']
        org_src_dataconf = dict(dataconf.items(org_src_name))
        self.org_src_reader = data_reader.DataReader(org_src_dataconf,
                                                     self.segment_lengths)

        #get the base signal (original mixture) reader
        base_name = conf['base']
        base_dataconf = dict(dataconf.items(base_name))
        self.base_reader = data_reader.DataReader(base_dataconf,
                                                  self.segment_lengths)

        #get the speaker info
        spkinfo_name = conf['spkinfo']
        spkinfo_dataconf = dict(dataconf.items(spkinfo_name))
        spkinfo_file = spkinfo_dataconf['datafiles']

        self.utt_spkinfo = dict()
        for line in open(spkinfo_file):
            splitline = line.strip().split(' ')
            utt_name = splitline[0]
            dataline = ' '.join(splitline[2:])
            self.utt_spkinfo[utt_name] = dataline

        #predefined mixture types
        self.mix_types = ['all_m', 'all_f', 'same_gen', 'diff_gen']

        #create the dictionary where all results will be stored
        self.results = dict()

        #metrics to be used in sumarize function, if not yet stated
        if not self.score_metrics_to_summarize:
            self.score_metrics_to_summarize = self.score_metrics

        noise_name = conf['noise']
        noise_dataconf = dict(dataconf.items(noise_name))
        self.noise_reader = data_reader.DataReader(noise_dataconf,
                                                   self.segment_lengths)
Exemplo n.º 2
0
    def __init__(self, conf, evalconf, dataconf, rec_dir, task):
        super(OracleReconstructor, self).__init__(conf, evalconf, dataconf,
                                                  rec_dir, task)

        #get the original mixtures reader
        noise_targets_name = conf['noise_targets']
        noise_targets_dataconf = dict(dataconf.items(noise_targets_name))
        self.noise_targets_reader = data_reader.DataReader(
            usedbins_dataconf, self.segment_lengths)
        binary_targets_name = conf['binary_targets']
        binary_targets_dataconf = dict(dataconf.items(noise_targets_name))
        self.binary_targets_reader = data_reader.DataReader()
	def __init__(self, conf, evalconf, dataconf, rec_dir, task, optimal_frame_permutation=False):
		"""DeepclusteringnoiseReconstructor constructor

		Args:
			conf: the reconstructor configuration as a dictionary
			evalconf: the evaluator configuration as a ConfigParser
			dataconf: the database configuration
			rec_dir: the directory where the reconstructions will be stored
			task: name of task
		"""

		super(DeepclusteringnoiseReconstructor, self).__init__(
			conf, evalconf, dataconf, rec_dir, task, optimal_frame_permutation)

		if 'noise_threshold_for_kmeans' in conf:
			self.noise_threshold = float(conf['noise_threshold_for_kmeans'])
		else:
			self.noise_threshold = 0.75
		if 'min_kmeans_perc' in conf:
			self.min_kmeans_perc = float(conf['min_kmeans_perc'])
		else:
			self.min_kmeans_perc = 0.05

		# get the usedbins reader
		usedbins_names = conf['usedbins'].split(' ')
		usedbins_dataconfs = []
		for usedbins_name in usedbins_names:
			usedbins_dataconfs.append(dict(dataconf.items(usedbins_name)))
		self.usedbins_reader = data_reader.DataReader(usedbins_dataconfs, self.segment_lengths)

		# directory where cluster centroids will be stored
		self.center_store_dir = os.path.join(rec_dir, 'cluster_centers')
		if not os.path.isdir(self.center_store_dir):
			os.makedirs(self.center_store_dir)
Exemplo n.º 4
0
	def __init__(self, conf, evalconf, dataconf, rec_dir, task, optimal_frame_permutation=False):
		"""StackedmasksReconstructor constructor

		Args:
			conf: the reconstructor configuration as a dictionary
			evalconf: the evaluator configuration as a ConfigParser
			dataconf: the database configuration
			rec_dir: the directory where the reconstructions will be stored
		"""

		if 'softmax_flag' in conf:
			raise Exception('Softmax argument is deprecated. Use output_activation')

		if 'output_activation' in conf:
			self.output_activation = conf['output_activation']
		else:
			self.output_activation = 'softmax'

		super(StackedmasksNoiseReconstructor, self).__init__(
			conf, evalconf, dataconf, rec_dir, task, optimal_frame_permutation)

		if optimal_frame_permutation:
			# get the usedbins reader
			usedbins_names = conf['usedbins'].split(' ')
			usedbins_dataconfs = []
			for usedbins_name in usedbins_names:
				usedbins_dataconfs.append(dict(dataconf.items(usedbins_name)))
			self.usedbins_reader = data_reader.DataReader(usedbins_dataconfs, self.segment_lengths)
    def __init__(self,
                 conf,
                 evalconf,
                 dataconf,
                 rec_dir,
                 task,
                 optimal_frame_permutation=False):
        """StackedmasksReconstructor constructor

		Args:
			conf: the reconstructor configuration as a dictionary
			evalconf: the evaluator configuration as a ConfigParser
			dataconf: the database configuration
			rec_dir: the directory where the reconstructions will be stored
		"""

        self.softmax_flag = True
        if 'softmax_flag' in conf and conf['softmax_flag'] == 'False':
            self.softmax_flag = False

        super(StackedmasksReconstructor,
              self).__init__(conf, evalconf, dataconf, rec_dir, task,
                             optimal_frame_permutation)

        if optimal_frame_permutation:
            # get the usedbins reader
            usedbins_names = conf['usedbins'].split(' ')
            usedbins_dataconfs = []
            for usedbins_name in usedbins_names:
                usedbins_dataconfs.append(dict(dataconf.items(usedbins_name)))
            self.usedbins_reader = data_reader.DataReader(
                usedbins_dataconfs, self.segment_lengths)
Exemplo n.º 6
0
    def __init__(self,
                 conf,
                 evalconf,
                 dataconf,
                 rec_dir,
                 task,
                 optimal_frame_permutation=False):
        # Whether the raw output should also be stored (besides the reconstructed audiosignal)
        self.store_output = conf['store_output'] == 'True'
        if self.store_output:
            self.output_dir = os.path.join(rec_dir, 'raw_output')
            if not os.path.isdir(self.output_dir):
                os.makedirs(self.output_dir)

            self.requested_output_names = conf['output_names'].split(' ')

            self.pos = 0
            if evalconf.has_option(task, 'batch_size'):
                self.batch_size = int(evalconf.get(task, 'batch_size'))
            else:
                self.batch_size = int(evalconf.get('evaluator', 'batch_size'))
            self.segment_lengths = evalconf.get('evaluator',
                                                'segment_length').split(' ')

            # get the original mixtures reader
            org_mix_names = conf['org_mix'].split(' ')
            org_mix_dataconfs = []
            for org_mix_name in org_mix_names:
                org_mix_dataconfs.append(dict(dataconf.items(org_mix_name)))
            self.org_mix_reader = data_reader.DataReader(
                org_mix_dataconfs, self.segment_lengths)
    def __init__(self, conf, evalconf, dataconf, rec_dir, task):
        '''DeepclusteringReconstructor constructor

        Args:
            conf: the reconstructor configuration as a dictionary
            evalconf: the evaluator configuration as a ConfigParser
            dataconf: the database configuration
            rec_dir: the directory where the reconstructions will be stored
        '''

        super(DeepclusteringReconstructor,
              self).__init__(conf, evalconf, dataconf, rec_dir, task)

        #get the usedbins reader
        usedbins_names = conf['usedbins'].split(' ')
        usedbins_dataconfs = []
        for usedbins_name in usedbins_names:
            usedbins_dataconfs.append(dict(dataconf.items(usedbins_name)))
        self.usedbins_reader = data_reader.DataReader(usedbins_dataconfs,
                                                      self.segment_lengths)

        #directory where cluster centroids will be stored
        self.center_store_dir = os.path.join(rec_dir, 'cluster_centers')
        if not os.path.isdir(self.center_store_dir):
            os.makedirs(self.center_store_dir)
Exemplo n.º 8
0
    def __init__(self,
                 conf,
                 evalconf,
                 dataconf,
                 rec_dir,
                 task,
                 optimal_frame_permutation=False):
        """MaskReconstructor constructor

		Args:
			conf: the reconstructor configuration as a dictionary
			evalconf: the evaluator configuration as a ConfigParser
			dataconf: the database configuration
			rec_dir: the directory where the reconstructions will be stored
		"""

        super(MaskReconstructor,
              self).__init__(conf, evalconf, dataconf, rec_dir, task,
                             optimal_frame_permutation)

        self.multi_mic_rec = False
        self.nrmic = 1
        if 'nrmic' in conf and int(conf['nrmic']) > 1:
            self.multi_mic_rec = True
            self.nrmic = int(conf['nrmic'])

        if not self.multi_mic_rec:
            # get the original mixtures reader
            org_mix_names = conf['org_mix'].split(' ')
            org_mix_dataconfs = []
            for org_mix_name in org_mix_names:
                org_mix_dataconfs.append(dict(dataconf.items(org_mix_name)))
            self.org_mix_reader = data_reader.DataReader(
                org_mix_dataconfs, self.segment_lengths)
        else:
            self.org_mix_readers = []
            for mic_ind in range(self.nrmic):
                org_mix_names = conf['org_mix_%d', (mic_ind + 1)].split(' ')
                org_mix_dataconfs = []
                for org_mix_name in org_mix_names:
                    org_mix_dataconfs.append(dict(
                        dataconf.items(org_mix_name)))
                self.org_mix_readers.append(
                    data_reader.DataReader(org_mix_dataconfs,
                                           self.segment_lengths))
Exemplo n.º 9
0
    def __init__(self, conf, dataconf, rec_dir, numbatches):
        '''Reconstructor constructor

        Args:
            conf: the evaluator configuration as a ConfigParser
            dataconf: the database configuration
            rec_dir: the directory where the reconstructions are
            numbatches: the number of batches to process
        '''

        self.conf = conf
        self.dataconf = dataconf
        self.tot_utt = int(conf.get('evaluator', 'batch_size')) * numbatches
        self.rec_dir = rec_dir
        self.segment_lengths = conf.get('evaluator',
                                        'segment_length').split(' ')

        #get the original source signals reader
        org_src_name = conf.get('scorer', 'org_src')
        org_src_dataconf = dict(dataconf.items(org_src_name))
        self.org_src_reader = data_reader.DataReader(org_src_dataconf,
                                                     self.segment_lengths)

        #get the base signal (original mixture) reader
        base_name = conf.get('scorer', 'base')
        base_dataconf = dict(dataconf.items(base_name))
        self.base_reader = data_reader.DataReader(base_dataconf,
                                                  self.segment_lengths)

        #get the speaker info
        spkinfo_name = conf.get('scorer', 'spkinfo')
        spkinfo_dataconf = dict(dataconf.items(spkinfo_name))
        spkinfo_file = spkinfo_dataconf['datafiles']

        self.utt_spkinfo = dict()
        for line in open(spkinfo_file):
            splitline = line.strip().split(' ')
            utt_name = splitline[0]
            dataline = ' '.join(splitline[1:])
            self.utt_spkinfo[utt_name] = dataline
#predefined mixture types
        self.mix_types = ['all_m', 'all_f', 'same_gen', 'diff_gen']

        #create the dictionary where all results will be stored
        self.results = dict()
Exemplo n.º 10
0
    def __init__(self, conf, dataconf, expdir):
        '''MaskReconstructor constructor

        Args:
            conf: the evaluator configuration as a ConfigParser
            dataconf: the database configurationn
            expdir: the experiment directory
        '''
        
        super(MaskReconstructor, self).__init__(conf, dataconf, expdir)
        
        #get the original mixtures reader 
        org_mix_name = conf.get('reconstructor','org_mix')
        org_mix_dataconf = dict(dataconf.items(org_mix_name))
        self.org_mix_reader = data_reader.DataReader(org_mix_dataconf, self.segment_lengths)
    def __init__(self, conf, evalconf, dataconf, rec_dir, task):
        '''ParallelMaskReconstructor constructor

        Args:
            conf: the reconstructor configuration as a dictionary
            evalconf: the evaluator configuration as a ConfigParser
            dataconf: the database configuration
            rec_dir: the directory where the reconstructions will be stored
        '''
        
        super(ParallelMaskReconstructor, self).__init__(conf, evalconf, dataconf, rec_dir, task)
        
        #get the original mixtures reader 
        org_mix_name = conf['org_mix']
        org_mix_dataconf = dict(dataconf.items(org_mix_name))
        self.org_mix_reader = data_reader.DataReader(org_mix_dataconf, self.segment_lengths)
	def __init__(self, conf, evalconf, dataconf, rec_dir, task):
		'''DeepclusteringXReconstructor constructor

        Args:
            conf: the reconstructor configuration as a dictionary
            evalconf: the evaluator configuration as a ConfigParser
            dataconf: the database configuration
            rec_dir: the directory where the reconstructions will be stored
        '''

		super(DeepXclusteringReconstructor, self).__init__(conf, evalconf, dataconf, rec_dir, task)

		#get the usedbins reader
		usedbins_name = conf['usedbins']
		usedbins_dataconf = dict(dataconf.items(usedbins_name))
		self.usedbins_reader = data_reader.DataReader(usedbins_dataconf,self.segment_lengths)
    def __init__(self, conf, dataconf, expdir):
        '''DeepclusteringReconstructor constructor

        Args:
            conf: the evaluator configuration as a ConfigParser
            dataconf: the database configurationn
            expdir: the experiment directory
        '''

        super(DeepclusteringReconstructor,
              self).__init__(conf, dataconf, expdir)

        #get the usedbins reader
        usedbins_name = conf.get('reconstructor', 'usedbins')
        usedbins_dataconf = dict(dataconf.items(usedbins_name))
        self.usedbins_reader = data_reader.DataReader(usedbins_dataconf,
                                                      self.segment_lengths)
Exemplo n.º 14
0
	def __init__(self, conf, evalconf, dataconf, rec_dir, task, optimal_frame_permutation=False):
		"""DeepclusteringReconstructor constructor

		Args:
			conf: the reconstructor configuration as a dictionary
			evalconf: the evaluator configuration as a ConfigParser
			dataconf: the database configuration
			rec_dir: the directory where the reconstructions will be stored
		"""

		super(OracleMaskReconstructor, self).__init__(
			conf, evalconf, dataconf, rec_dir, task, optimal_frame_permutation)

		# get the binarytargets reader
		binarytargets_names = conf['binary_targets'].split(' ')
		binarytargets_dataconfs = []
		for binarytargets_name in binarytargets_names:
			binarytargets_dataconfs.append(dict(dataconf.items(binarytargets_name)))
		self.binarytargets_reader = data_reader.DataReader(binarytargets_dataconfs, self.segment_lengths)
    def __init__(self, conf, evalconf, dataconf, rec_dir, task):
        '''DeepclusteringReconstructor constructor

        Args:
        conf: the reconstructor configuration as a dictionary
        evalconf: the evaluator configuration as a ConfigParser
        dataconf: the database configuration
        rec_dir: the directory where the reconstructions will be stored'''

        super(DeepattractornoisehardReconstructor, self).__init__(conf, evalconf, dataconf, rec_dir, task)

        #get the usedbins reader
        mix_to_mask_name = conf['mix_to_mask']
        mix_to_mask_dataconf = dict(dataconf.items(mix_to_mask_name))
        self.mix_to_mask_reader = data_reader.DataReader(mix_to_maks_dataconf,self.segment_lengths)

        #directory where cluster centroids will be stored
        self.center_store_dir = os.path.join(rec_dir,'cluster_centers')
        if not os.path.isdir(self.center_store_dir):
            os.makedirs(self.center_store_dir)
Exemplo n.º 16
0
    def __init__(self, conf, evalconf, dataconf, rec_dir, task):
        '''MaskReconstructor constructor

        Args:
            conf: the reconstructor configuration as a dictionary
            evalconf: the evaluator configuration as a ConfigParser
            dataconf: the database configuration
            rec_dir: the directory where the reconstructions will be stored
        '''

        super(MaskReconstructor, self).__init__(conf, evalconf, dataconf,
                                                rec_dir, task)

        #get the original mixtures reader
        org_mix_names = conf['org_mix'].split(' ')
        org_mix_dataconfs = []
        for org_mix_name in org_mix_names:
            org_mix_dataconfs.append(dict(dataconf.items(org_mix_name)))
        self.org_mix_reader = data_reader.DataReader(org_mix_dataconfs,
                                                     self.segment_lengths)
Exemplo n.º 17
0
    def __init__(self, conf, evalconf, dataconf, rec_dir, numbatches, task,
                 scorer_name, checkpoint_file):
        """Reconstructor constructor
		Args:
			conf: the scorer configuration as a dictionary
			evalconf: the evaluator configuration as a ConfigParser
			dataconf: the database configuration
			rec_dir: the directory where the reconstructions are
			numbatches: the number of batches to process
		"""

        super(SdrSnrNoiseScorer,
              self).__init__(conf, evalconf, dataconf, rec_dir, numbatches,
                             task, scorer_name, checkpoint_file)

        # get the original noise signal reader
        noise_names = conf['noise'].split(' ')
        noise_dataconfs = []
        for noise_name in noise_names:
            noise_dataconfs.append(dict(dataconf.items(noise_name)))
        self.noise_reader = data_reader.DataReader(noise_dataconfs,
                                                   self.segment_lengths)
Exemplo n.º 18
0
    def __init__(self, conf, evalconf, dataconf, store_dir, numbatches, task,
                 scorer_name, checkpoint_file):
        """Scorer constructor

		Args:
			conf: the scorer configuration as a dictionary
			evalconf: the evaluator configuration as a ConfigParser
			dataconf: the database configuration
			store_dir: the directory where the reconstructions are
			numbatches: the number of batches to process
		"""

        if evalconf.has_option(task, 'batch_size'):
            batch_size = int(evalconf.get(task, 'batch_size'))
        else:
            batch_size = int(evalconf.get('evaluator', 'batch_size'))
        self.tot_utt = batch_size * numbatches
        self.store_dir = store_dir
        self.segment_lengths = evalconf.get('evaluator',
                                            'segment_length').split(' ')

        # get the feature input reader, only to get the name of the utterance actually.
        input_features_names = conf['input_features'].split(' ')
        input_features_dataconfs = []
        for input_features_name in input_features_names:
            input_features_dataconfs.append(
                dict(dataconf.items(input_features_name)))
        self.input_features_reader = data_reader.DataReader(
            input_features_dataconfs, self.segment_lengths)

        if 'nrs' in conf:
            self.nrS = int(conf['nrs'])

        # create the dictionary where all results will be stored
        self.results = dict()

        self.pos = 0
        self.scorer_name = scorer_name
    def __init__(self,
                 conf,
                 evalconf,
                 dataconf,
                 rec_dir,
                 task,
                 optimal_frame_permutation=False):
        """DeepclusteringReconstructor constructor

		Args:
			conf: the reconstructor configuration as a dictionary
			evalconf: the evaluator configuration as a ConfigParser
			dataconf: the database configuration
			rec_dir: the directory where the reconstructions will be stored
		"""

        super(DeepclusteringReconstructor,
              self).__init__(conf, evalconf, dataconf, rec_dir, task,
                             optimal_frame_permutation)

        # get the usedbins reader
        usedbins_names = conf['usedbins'].split(' ')
        usedbins_dataconfs = []
        for usedbins_name in usedbins_names:
            usedbins_dataconfs.append(dict(dataconf.items(usedbins_name)))
        self.usedbins_reader = data_reader.DataReader(usedbins_dataconfs,
                                                      self.segment_lengths)

        # directory where cluster centroids will be stored
        self.center_store_dir = os.path.join(rec_dir, 'cluster_centers')
        if not os.path.isdir(self.center_store_dir):
            os.makedirs(self.center_store_dir)

        # whether output will be in [time x freq_dim*emb_dim] or
        # [time x freq_dim x emb_dim]
        self.flat = False
        if 'flat' in conf['reconstruct_type']:
            self.flat = True
Exemplo n.º 20
0
    def __init__(self,
                 conf,
                 evalconf,
                 dataconf,
                 rec_dir,
                 task,
                 optimal_frame_permutation=False):
        """DeepclusteringReconstructor constructor

        Args:
        conf: the reconstructor configuration as a dictionary
        evalconf: the evaluator configuration as a ConfigParser
        dataconf: the database configuration
        rec_dir: the directory where the reconstructions will be stored
        task: task name
        """

        warnings.warn(
            'In following versions this function will become deprecated. Use deepattractornet_reconstructor.py instead',
            Warning)

        super(DeepattractorSoftmaxReconstructor,
              self).__init__(conf, evalconf, dataconf, rec_dir, task,
                             optimal_frame_permutation)

        # get the usedbins reader
        usedbins_names = conf['usedbins'].split(' ')
        usedbins_dataconfs = []
        for usedbins_name in usedbins_names:
            usedbins_dataconfs.append(dict(dataconf.items(usedbins_name)))
        self.usedbins_reader = data_reader.DataReader(usedbins_dataconfs,
                                                      self.segment_lengths)

        # directory where cluster centroids will be stored
        self.center_store_dir = os.path.join(rec_dir, 'cluster_centers')
        if not os.path.isdir(self.center_store_dir):
            os.makedirs(self.center_store_dir)
Exemplo n.º 21
0
task_evaluator_cfg = dict(evaluator_cfg.items(task))
task_reconstructor_cfg = dict(reconstructor_cfg.items(task))

database_cfg = configparser.ConfigParser()
database_cfg.read(os.path.join(expdir, 'database.cfg'))

noise_targets_name = task_evaluator_cfg['noise_targets']
noise_targets_dataconf = dict(database_cfg.items(noise_targets_name))

binary_targets_name = task_evaluator_cfg['binary_targets']
binary_targets_dataconf = dict(database_cfg.items(binary_targets_name))

org_mix_name = task_reconstructor_cfg['org_mix']
org_mix_dataconf = dict(database_cfg.items(org_mix_name))

noise_targets_reader = data_reader.DataReader(noise_targets_dataconf)
binary_targets_reader = data_reader.DataReader(binary_targets_dataconf)
org_mix_reader = data_reader.DataReader(org_mix_dataconf)


if not os.path.isdir(os.path.join(rec_dir)):
    os.makedirs(os.path.join(rec_dir))
scp_file = open(os.path.join(rec_dir,'pointers.scp'),'w+')

# Make storage folders
#for spk in range(nrS):
    if not os.path.isdir(os.path.join(rec_dir,'s' + str(spk+1))):
        os.makedirs(os.path.join(rec_dir,'s' + str(spk+1)))

for i in range(0,3000):
    if i%10 == 0:
    def __init__(self, conf, evalconf, dataconf, store_dir, exp_dir, task):

        super(AttractorFromEmbeddings, self).__init__(conf, evalconf, dataconf,
                                                      store_dir, exp_dir, task)

        self.cut_to_seq_length = True

        self.emb_dim = int(conf['emb_dim'])

        self.task_for_masks = self.conf['task_for_masks']
        if self.task_for_masks in ['here', 'None', task]:
            # Find the masks here. This only makes sense if the same embeddings were used for the speaker separation and
            # speaker recognition task
            raise NotImplementedError()
        else:
            masks_pointer_file = os.path.join(exp_dir, 'reconstructions',
                                              self.task_for_masks,
                                              'masks_pointers.scp')
            self.mix2maskfile = dict()
            with open(masks_pointer_file, 'r') as masks_pointer_fid:
                for line in masks_pointer_fid:
                    splitline = line.strip('\n').split(' ')
                    self.mix2maskfile[splitline[0]] = splitline[1]

            if 'score_type_for_perm' not in conf:
                raise BaseException('')
            result_file = os.path.join(
                exp_dir, 'results_%s_%s_complete.json' %
                (self.task_for_masks, conf['score_type_for_perm']))
            with open(result_file, 'r') as result_fid:
                all_results = json.load(result_fid)
            self.mix2permutation = {
                name: all_results[name]['score']['perm']['SS']
                for name in all_results.keys()
            }

        if 'thr_for_mask' in conf:
            self.thr_for_mask = float(conf['thr_for_mask'])
            self.binary_masks = conf['binary_masks'] == 'True'
            if not self.binary_masks:
                self.rescale_masks = conf['rescale_masks'] == 'True'
        else:
            self.thr_for_mask = False

        usedbins_names = conf['usedbins'].split(' ')
        usedbins_dataconfs = []
        for usedbins_name in usedbins_names:
            usedbins_dataconfs.append(dict(dataconf.items(usedbins_name)))
        self.usedbins_reader = data_reader.DataReader(usedbins_dataconfs,
                                                      self.segment_lengths)

        if 'normalization' not in self.conf or self.conf[
                'normalization'] == 'True':
            self.normalization = True
        else:
            self.normalization = False

        if 'output_names' in self.conf:
            self.requested_output_names = self.conf['output_names'].split(' ')
        else:
            self.requested_output_names = self.base_requested_output_names
        if len(self.requested_output_names) > 1:
            raise BaseException(
                'Expected the amount of requested output names to be one, but was %d instead'
                % len(self.requested_output_names))
Exemplo n.º 23
0
    def __init__(self, conf, evalconf, dataconf, rec_dir, numbatches, task,
                 scorer_name, checkpoint_file):
        """Scorer constructor

		Args:
			conf: the scorer configuration as a dictionary
			evalconf: the evaluator configuration as a ConfigParser
			dataconf: the database configuration
			rec_dir: the directory where the reconstructions are
			numbatches: the number of batches to process
		"""

        if evalconf.has_option(task, 'batch_size'):
            batch_size = int(evalconf.get(task, 'batch_size'))
        else:
            batch_size = int(evalconf.get('evaluator', 'batch_size'))
        self.tot_utt = batch_size * numbatches
        self.rec_dir = rec_dir
        self.segment_lengths = evalconf.get('evaluator',
                                            'segment_length').split(' ')

        # get the target reader (typically the original source signals)
        target_names = conf[self.target_name].split(' ')
        target_dataconfs = []
        for target_name in target_names:
            target_dataconfs.append(dict(dataconf.items(target_name)))
        self.target_reader = data_reader.DataReader(target_dataconfs,
                                                    self.segment_lengths)

        # get the base signal (original mixture) reader
        base_names = conf['base'].split(' ')
        base_dataconfs = []
        for base_name in base_names:
            base_dataconfs.append(dict(dataconf.items(base_name)))
        self.base_reader = data_reader.DataReader(base_dataconfs,
                                                  self.segment_lengths)

        if 'select_indices' in conf:
            select_indices_names = conf['select_indices'].split(' ')
            select_indices_dataconfs = []
            for select_indices_name in select_indices_names:
                select_indices_dataconfs.append(
                    dict(dataconf.items(select_indices_name)))
            self.select_indices_reader = data_reader.DataReader(
                select_indices_dataconfs, self.segment_lengths)
        else:
            self.select_indices_reader = False

        if 'nrs' in conf:
            self.nrS = int(conf['nrs'])

        # get the speaker info
        self.utt_spkinfo = dict()
        spkinfo_names = conf['spkinfo'].split(' ')
        for spkinfo_name in spkinfo_names:
            spkinfo_dataconf = dict(dataconf.items(spkinfo_name))
            spkinfo_file = spkinfo_dataconf['datafiles']

            for line in open(spkinfo_file):
                splitline = line.strip().split(' ')
                utt_name = splitline[0]
                dataline = ' '.join(splitline[2:])
                self.utt_spkinfo[utt_name] = dataline
        # predefined mixture types
        self.mix_types = ['all_m', 'all_f', 'same_gen', 'diff_gen']
        # metrics to be used in sumarize function, if not yet stated
        if not self.score_metrics_to_summarize:
            self.score_metrics_to_summarize = self.score_metrics

        if 'score_from' in conf and conf['score_from'] == 'True':
            if self.score_expects != 'data':
                raise Exception(
                    'Can only score from a specific timestamp on if scorer expects data'
                )
            else:
                self.score_from = True
        else:
            self.score_from = False

        if 'score_center_samples_num' in conf:
            if self.score_expects != 'data':
                raise BaseException('')
            else:
                self.score_center_samples_num = int(
                    conf['score_center_samples_num'])
                self.score_center_samples_num = float(
                    self.score_center_samples_num)
        else:
            self.score_center_samples_num = False

        if 'load_rec_as_numpy' in conf:
            self.load_rec_as_numpy = conf['load_rec_as_numpy'] in [
                'True', 'true'
            ]
        else:
            self.load_rec_as_numpy = False

        # create the dictionary where all results will be stored
        self.results = dict()

        self.checkpoint_file = checkpoint_file
        if self.checkpoint_file:
            if os.path.isfile(self.checkpoint_file):
                with open(self.checkpoint_file, 'r') as fid:
                    self.results = json.load(fid)
                    self.start_ind = len(self.results.keys())
            else:
                self.start_ind = 0
        else:
            self.start_ind = 0
Exemplo n.º 24
0
task_reconstructor_cfg = dict(reconstructor_cfg.items(task))

# General database file
database_cfg = configparser.ConfigParser()
database_cfg.read(os.path.join(expdir, 'database.cfg'))

# partition targets (ground truth)
partition_targets_name = task_evaluator_cfg['binary_targets']
partition_targets_dataconf = dict(database_cfg.items(partition_targets_name))

# spectrogram original mixture
org_mix_name = task_reconstructor_cfg['org_mix']
org_mix_dataconf = dict(database_cfg.items(org_mix_name))

# read from dataforTF files
partition_targets_reader = data_reader.DataReader(partition_targets_dataconf)
org_mix_reader = data_reader.DataReader(org_mix_dataconf)

# Create reconstruction directory
if not os.path.isdir(os.path.join(rec_dir)):
    os.makedirs(os.path.join(rec_dir))
# File with all files
scp_file = open(os.path.join(rec_dir,'pointers.scp'),'w+')

# Make storage folders
for spk in range(nrS):
    if not os.path.isdir(os.path.join(rec_dir,'s' + str(spk+1))):
        os.makedirs(os.path.join(rec_dir,'s' + str(spk+1)))
for i in range(0,3000):
    if i%10 == 0:
        print "reconstructing ",i
    def __init__(self, conf, evalconf, dataconf, store_dir, exp_dir, task):
        """Reconstructor constructor

		Args:
			conf: the reconstructor configuration as a dictionary
			evalconf: the evaluator configuration as a ConfigParser
			dataconf: the database configuration
			store_dir: the directory where the handled data will be stored
		"""

        self.conf = conf
        self.dataconf = dataconf
        if evalconf.has_option(task, 'batch_size'):
            self.batch_size = int(evalconf.get(task, 'batch_size'))
        else:
            self.batch_size = int(evalconf.get('evaluator', 'batch_size'))
        self.segment_lengths = evalconf.get('evaluator',
                                            'segment_length').split(' ')

        self.nrS = int(conf['nrs'])

        if 'transpose_order' in conf:
            self.transpose_order = map(int, conf['transpose_order'].split(' '))
        else:
            self.transpose_order = False

        if 'cut_to_seq_length' not in conf or conf[
                'cut_to_seq_length'] == 'True':
            self.cut_to_seq_length = True
        else:
            self.cut_to_seq_length = False

        # create the directory to write down the reconstructions
        self.store_dir = store_dir
        if not os.path.isdir(self.store_dir):
            os.makedirs(self.store_dir)
        if not os.path.isdir(os.path.join(self.store_dir, 'data')):
            os.makedirs(os.path.join(self.store_dir, 'data'))
        # for spk in range(self.nrS):
        # 	if not os.path.isdir(os.path.join(self.store_dir, 's' + str(spk+1))):
        # 		os.makedirs(os.path.join(self.store_dir, 's' + str(spk+1)))

        # the use of the position variable only works because in the evaluator the
        # shuffle option in the data_queue is set to False!!
        self.pos = 0

        # Whether the raw output should also be stored
        self.store_output = conf['store_output'] == 'True'
        if self.store_output:
            self.raw_output_dir = os.path.join(store_dir, 'raw_output')
            if not os.path.isdir(self.raw_output_dir):
                os.makedirs(self.raw_output_dir)

        # get the feature input reader, only to get the name of the utterance actually.
        input_features_names = conf['input_features'].split(' ')
        input_features_dataconfs = []
        for input_features_name in input_features_names:
            input_features_dataconfs.append(
                dict(dataconf.items(input_features_name)))
        self.input_features_reader = data_reader.DataReader(
            input_features_dataconfs, self.segment_lengths)
Exemplo n.º 26
0
evaluator_cfg = configparser.ConfigParser()
evaluator_cfg.read(os.path.join(expdir, 'evaluator.cfg'))

task_evaluator_cfg = dict(evaluator_cfg.items(task))

database_cfg = configparser.ConfigParser()
database_cfg.read(os.path.join(expdir, 'database.cfg'))

binary_targets_name = task_evaluator_cfg['partitioning']
binary_targets_dataconf = dict(database_cfg.items(binary_targets_name))

energybin_targets_name = task_evaluator_cfg['energybins']
energybin_targets_dataconf = dict(database_cfg.items(energybin_targets_name))

energybin_targets_reader = data_reader.DataReader(energybin_targets_dataconf)
binary_targets_reader = data_reader.DataReader(binary_targets_dataconf)

i = 2719

energybins, utt_info = energybin_targets_reader(i)
energybins_shape = np.shape(energybins)
energybins = np.reshape(energybins, energybins_shape[0] * energybins_shape[1])
emb_vec = np.load(
    os.path.join(rawoutputdir, 'emb_vec_' + utt_info['utt_name'] + '.npy'))
center = np.load(os.path.join(centerdir, utt_info['utt_name'] + '.npy'))

binary_targets_complete, _ = binary_targets_reader(i)
binary_targets_spk1 = binary_targets_complete[:, ::nrS]
binary_targets_spk1 = np.reshape(binary_targets_spk1,
                                 energybins_shape[0] * energybins_shape[1])
Exemplo n.º 27
0
    def __init__(self, conf, evalconf, dataconf, rec_dir, numbatches, task):
        '''Reconstructor constructor

        Args:
            conf: the scorer configuration as a dictionary
            evalconf: the evaluator configuration as a ConfigParser
            dataconf: the database configuration
            rec_dir: the directory where the reconstructions are
            numbatches: the number of batches to process
        '''

	if evalconf.has_option(task,'batch_size'):
	    batch_size = int(evalconf.get(task,'batch_size'))
	else:
	    batch_size = int(evalconf.get('evaluator','batch_size'))
        self.tot_utt = batch_size * numbatches
        self.rec_dir = rec_dir
        self.segment_lengths = evalconf.get('evaluator','segment_length').split(' ')
	    
        #get the original source signals reader 
        org_src_names = conf['org_src'].split(' ')
        org_src_dataconfs=[]
        for org_src_name in org_src_names:
	    org_src_dataconfs.append(dict(dataconf.items(org_src_name)))
        self.org_src_reader = data_reader.DataReader(org_src_dataconfs,self.segment_lengths)
        
        #get the base signal (original mixture) reader 
        base_names = conf['base'].split(' ')
        base_dataconfs=[]
        for base_name in base_names:
	    base_dataconfs.append(dict(dataconf.items(base_name)))
        self.base_reader = data_reader.DataReader(base_dataconfs,self.segment_lengths)
        
        #get the speaker info
        self.utt_spkinfo = dict()
        spkinfo_names = conf['spkinfo'].split(' ')
        for spkinfo_name in spkinfo_names:
	    spkinfo_dataconf=dict(dataconf.items(spkinfo_name))
	    spkinfo_file = spkinfo_dataconf['datafiles']
        
	    for line in open(spkinfo_file):
		splitline = line.strip().split(' ')
		utt_name = splitline[0]
		dataline = ' '.join(splitline[2:])
		self.utt_spkinfo[utt_name] = dataline
	#predefined mixture types
	self.mix_types = ['all_m', 'all_f','same_gen', 'diff_gen']
        
        #create the dictionary where all results will be stored
        self.results = dict()
        
        #metrics to be used in sumarize function, if not yet stated
	if not self.score_metrics_to_summarize:
	    self.score_metrics_to_summarize = self.score_metrics
	    
	if 'score_from' in conf and conf['score_from']=='True':
	    if self.score_expects!='data':
		raise('Can only score from a specific timestamp on if scorer expects data')
	    else:
		self.score_from=True   
	else:
	    self.score_from=False