def get_embeddings(self): X_train, y_train, s_list_train = load_test_data( self.get_validation_train_data()) X_test, y_test, s_list_test = load_test_data( self.get_validation_test_data()) embeddings, speakers, num_embeddings, time = self.cnn.create_embeddings( X_train, y_train, X_test, y_test) return [self.checkpoint], [embeddings], [speakers], [num_embeddings ], [time]
def get_embeddings(self): short_utterance = self.config.getboolean('validation', 'short_utterances') logger = get_logger('kldiv', logging.INFO) logger.info('Run pairwise_kldiv') checkpoints = self.checkpoints X_train, y_train, s_list_train = load_test_data( self.get_validation_train_data()) X_test, y_test, s_list_test = load_test_data( self.get_validation_test_data()) x_list, y_list, s_list = create_data_lists(short_utterance, X_train, X_test, y_train, y_test, s_list_train, s_list_test) # Prepare return value set_of_embeddings = [] set_of_speakers = [] set_of_num_embeddings = [] set_of_total_times = [] for checkpoint in checkpoints: logger.info('Run checkpoint: ' + checkpoint) network_file = get_experiment_nets(checkpoint) x_cluster_list = [] y_cluster_list = [] for x, y, s in zip(x_list, y_list, s_list): x_cluster, y_cluster = run_analysis_network( network_file, x, y, s) x_cluster_list.append(x_cluster) y_cluster_list.append(y_cluster) embeddings, speakers, num_embeddings =\ generate_embeddings(x_cluster_list, y_cluster_list, x_cluster_list[0].shape[1]) # Fill return values set_of_embeddings.append(embeddings) set_of_speakers.append(speakers) set_of_num_embeddings.append(num_embeddings) # Calculate the time per utterance time = TimeCalculator.calc_time_all_utterances( y_cluster_list, config.getint('pairwise_kldiv', 'seg_size')) set_of_total_times.append(time) return checkpoints, set_of_embeddings, set_of_speakers, set_of_num_embeddings, set_of_total_times
def get_embeddings(self): # Get settings short_utterance = self.config.getboolean('test', 'short_utterances') out_layer = self.config.getint('pairwise_kldiv', 'out_layer') seg_size = self.config.getint('pairwise_kldiv', 'seg_size') self.logger.info('Run pairwise_kldiv') # Load and prepare test data X_long, y_long, s_list_long = load_test_data(self.get_validation_train_data()) X_short, y_short, s_list_short = load_test_data(self.get_validation_test_data()) X_long, y_long = self._prepare_data(X_long, y_long) X_short, y_short = self._prepare_data(X_short, y_short) x_list, y_list, _ = create_data_lists(short_utterance, X_long, X_short, y_long, y_short, s_list_long, s_list_short) embeddings_data = create_embeddings(self.config, self.checkpoints, x_list, y_list, out_layer, seg_size) return embeddings_data
def get_embeddings(self): short_utterance = self.config.getboolean('validation', 'short_utterances') out_layer = self.config.getint('pairwise_lstm', 'out_layer') seg_size = self.config.getint('pairwise_lstm', 'seg_size') vec_size = self.config.getint('pairwise_lstm', 'vec_size') logger = get_logger('lstm', logging.INFO) logger.info('Run pairwise_lstm test') logger.info('out_layer -> ' + str(out_layer)) logger.info('seg_size -> ' + str(seg_size)) logger.info('vec_size -> ' + str(vec_size)) # Load and prepare train/test data x_train, speakers_train, s_list_train = load_test_data( self.get_validation_train_data()) x_test, speakers_test, s_list_test = load_test_data( self.get_validation_test_data()) x_train, speakers_train, = prepare_data(x_train, speakers_train, seg_size) x_test, speakers_test = prepare_data(x_test, speakers_test, seg_size) x_list, y_list, s_list = create_data_lists(short_utterance, x_train, x_test, speakers_train, speakers_test, s_list_train, s_list_test) # Prepare return values set_of_embeddings = [] set_of_speakers = [] speaker_numbers = [] set_of_total_times = [] checkpoints = list_all_files(get_experiment_nets(), "^pairwise_lstm.*\.h5") # Values out of the loop metrics = [ 'accuracy', 'categorical_accuracy', ] loss = pairwise_kl_divergence custom_objects = {'pairwise_kl_divergence': pairwise_kl_divergence} optimizer = 'rmsprop' vector_size = vec_size #256 * 2 # Fill return values for checkpoint in checkpoints: logger.info('Running checkpoint: ' + checkpoint) # Load and compile the trained network network_file = get_experiment_nets(checkpoint) model_full = load_model(network_file, custom_objects=custom_objects) model_full.compile(loss=loss, optimizer=optimizer, metrics=metrics) # Get a Model with the embedding layer as output and predict model_partial = Model(inputs=model_full.input, outputs=model_full.layers[out_layer].output) x_cluster_list = [] y_cluster_list = [] for x, y, s in zip(x_list, y_list, s_list): x_cluster = np.asarray(model_partial.predict(x)) x_cluster_list.append(x_cluster) y_cluster_list.append(y) embeddings, speakers, num_embeddings = generate_embeddings( x_cluster_list, y_cluster_list, vector_size) # Fill the embeddings and speakers into the arrays set_of_embeddings.append(embeddings) set_of_speakers.append(speakers) speaker_numbers.append(num_embeddings) # Calculate the time per utterance time = TimeCalculator.calc_time_all_utterances( y_cluster_list, seg_size) set_of_total_times.append(time) logger.info('Pairwise_lstm test done.') return checkpoints, set_of_embeddings, set_of_speakers, speaker_numbers, set_of_total_times