def get_waliji_feature_map(s, log_part_blocks, log_invpart_blocks, abst_threshold=np.array([.025,.025,.015,.015, .02,.02,.02,.02]), spread_length=3, fft_length=512, num_window_step_samples=80, freq_cutoff=3000, sample_rate=16000, num_window_samples=320, kernel_length=7): """ Input is usually just the signal s as the rest of the parameters are not going to change very often Parameters: =========== s: np.ndarray[ndim=1] Raw signal data that we are extracting feature from log_part_blocks: np.ndarray[ndim=4,dtype=np.float32] First dimension is over the different features log_invpart_blocks: np.ndarray[ndim=4,dtype=np.float32] Essentially the same array as log_part_blocks. Related by its equal to np.log(1-np.exp(log_part_blocks)) """ S = esp.get_spectrogram_features(s, sample_rate, num_window_samples, num_window_step_samples, fft_length, freq_cutoff, kernel_length, ) E, edge_feature_row_breaks,\ edge_orientations = esp._edge_map_no_threshold(S) esp._edge_map_threshold_segments(E, 40, 1, threshold=.7, edge_orientations = edge_orientations, edge_feature_row_breaks = edge_feature_row_breaks) E = reorg_part_for_fast_filtering(E) F = cp.code_parts_fast(E.astype(np.uint8),log_part_blocks,log_invpart_blocks,10) F = np.argmax(F,2) # the amount of spreading to do is governed by the size of the part features F = swp.spread_waliji_patches(F, log_part_blocks.shape[1], log_part_blocks.shape[2], log_part_blocks.shape[0]) return collapse_to_grid(F,log_part_blocks.shape[1], log_part_blocks.shape[2])
patches_by_8 = np.array([ E[i/S.shape[1]: i/S.shape[1]+5, i%S.shape[1]: (i%S.shape[1])+5,:] S_patches_by_8 = np.array([ S[i/S.shape[1]: i/S.shape[1]+5, i%S.shape[1]: i%S.shape[1]+5] for i in patch_idx_detected_by8]) out_map = np.argmax(out_map,2) # the amount of spreading to do is governed by the size of the part features out_map = swp.spread_waliji_patches(out_map, log_parts.shape[1], log_parts.shape[2], log_parts.shape[0]) out_map = gtrd.collapse_to_grid(out_map,log_parts.shape[1], log_parts.shape[2]) fl_idx = 0 fl = file_indices[fl_idx] utterance = gtrd.makeUtterance(utterances_path,fl) S = gtrd.get_spectrogram(utterance.s,sp) E = gtrd.get_edge_features(S.T,ep,verbose=False)