def generate_decoders_data(data_dir, data_extension): # File reader won't work, so I need to load audio files into external_source manually fnames = test_utils.filter_files(data_dir, data_extension) nfiles = len(fnames) _input_epoch = [ list( map(lambda fname: test_utils.read_file_bin(fname), fnames[:nfiles // 3])), list( map(lambda fname: test_utils.read_file_bin(fname), fnames[nfiles // 3:nfiles // 2])), list( map(lambda fname: test_utils.read_file_bin(fname), fnames[nfiles // 2:])), ] # Since we pack buffers into ndarray, we need to pad samples with 0. input_epoch = [] for inp in _input_epoch: max_len = max(sample.shape[0] for sample in inp) inp = map( lambda sample: np.pad(sample, (0, max_len - sample.shape[0])), inp) input_epoch.append(np.stack(list(inp))) input_epoch = list( map(lambda batch: np.reshape(batch, batch.shape), input_epoch)) return input_epoch
def generate_decoders_data(data_dir, data_extension): # File reader won't work, so I need to load audio files into external_source manually fnames = test_utils.filter_files(data_dir, data_extension) nfiles = len(fnames) # TODO(janton): Workaround for audio data (not enough samples) # To be removed when more audio samples are added for i in range(len(fnames), 10): # At least 10 elements fnames.append(fnames[-1]) nfiles = len(fnames) _input_epoch = [ list(map(lambda fname: test_utils.read_file_bin(fname), fnames[:nfiles // 3])), list(map(lambda fname: test_utils.read_file_bin(fname), fnames[nfiles // 3: nfiles // 2])), list(map(lambda fname: test_utils.read_file_bin(fname), fnames[nfiles // 2:])), ] # Since we pack buffers into ndarray, we need to pad samples with 0. input_epoch = [] for inp in _input_epoch: max_len = max(sample.shape[0] for sample in inp) inp = map(lambda sample: np.pad(sample, (0, max_len - sample.shape[0])), inp) input_epoch.append(np.stack(list(inp))) input_epoch = list(map(lambda batch: np.reshape(batch, batch.shape), input_epoch)) return input_epoch