voxseg_/evaluate.py
def _segments_to_mask(wav_scp: pd.DataFrame, segments: pd.DataFrame, frame_length: float = 0.01) -> Dict[str,np.ndarray]:
    '''Auxillary function used by score(). Creates a dictionary of recording-ids to np.ndarrays,
    which are boolean masks indicating the presence of segments within a recording.

    Args:
        wav_scp: A pd.DataFrame containing wav file data in the following columns:
            [recording-id, extended filename]
        segments: A pd.DataFrame containing segments file data in the following columns:
            [utterance-id, recording-id, start, end]
        frame_length (optional): The length of the frames used for scoring in seconds. (Default: 0.01)

    Returns:
        A dictionary mapping recording-ids to np.ndarrays, which are boolean masks of the frames
        which makeup segments within a recording.

    Example:
        A 0.1 second clip with a segment starting at 0.03 and ending 0.07 would yeild a mask:
        [0, 0, 0, 1, 1, 1, 1, 0, 0, 0]
    '''

    wav_scp = wav_scp.copy()
    wav_scp['duration'] = wav_scp['extended filename'].apply(lambda x: len(wavfile.read(x)[1])/wavfile.read(x)[0]).astype(float)    
    wav_scp['mask'] = round(wav_scp['duration'] / frame_length).astype(int).apply(np.zeros)

    segments = segments.copy()    
    segments['frames'] = (round(segments['end'] / frame_length).astype(int) - \
                          round(segments['start'] / frame_length).astype(int)).apply(np.ones)
   
    #segments['frames'] = segments.apply(lambda x: np.ones(math.ceil(x['end']/frame_length) - math.floor(x['start']/frame_length)), axis=1)
    
    temp = wav_scp.merge(segments, how='left', on='recording-id')

    for n,_ in enumerate(temp['mask']):
                
        if not np.isnan(temp['start'][n]):                        
            temp['mask'][n][round(temp['start'][n] / frame_length):round(temp['end'][n] / frame_length)] = temp['frames'][n]
            #temp['mask'][n][math.floor(temp['start'][n] / frame_length):math.ceil(temp['end'][n] / frame_length)] = temp['frames'][n]
            
    if len(wav_scp.index) > 1:
        wav_scp['mask'] = temp['mask'].drop_duplicates().reset_index(drop=True)
    else:
        wav_scp['mask'] = temp['mask']
    return wav_scp[['recording-id', 'mask']].set_index('recording-id')['mask'].to_dict()
Auxillary function used by score(). Creates a dictionary of recording-ids to np.ndarrays,
    which are boolean masks indicating the presence of segments within a recording.

    Args:
        wav_scp: A pd.DataFrame containing wav file data in the following columns:
            [recording-id, extended filename]
        segments: A pd.DataFrame containing segments file data in the following columns:
            [utterance-id, recording-id, start, end]
        frame_length (optional): The length of the frames used for scoring in seconds. (Default: 0.01)

    Returns:
        A dictionary mapping recording-ids to np.ndarrays, which are boolean masks of the frames
        which makeup segments within a recording.

    Example:
        A 0.1 second clip with a segment starting at 0.03 and ending 0.07 would yeild a mask:
        [0, 0, 0, 1, 1, 1, 1, 0, 0, 0]
    
Auxillary function used by score(). Creates a dictionary of recording-ids to np.ndarrays,
which are boolean masks indicating the presence of segments within a recording.
Auxillary function used by score () . Creates a dictionary of recording - ids to np . ndarrays which are boolean masks indicating the presence of segments within a recording .
def _segments_to_mask(wav_scp: pd.DataFrame, segments: pd.DataFrame, frame_length: float = 0.01) -> Dict[str,np.ndarray]:
    wav_scp = wav_scp.copy()
    wav_scp['duration'] = wav_scp['extended filename'].apply(lambda x: len(wavfile.read(x)[1])/wavfile.read(x)[0]).astype(float)    
    wav_scp['mask'] = round(wav_scp['duration'] / frame_length).astype(int).apply(np.zeros)
    segments = segments.copy()    
    segments['frames'] = (round(segments['end'] / frame_length).astype(int) - \
                          round(segments['start'] / frame_length).astype(int)).apply(np.ones)
    temp = wav_scp.merge(segments, how='left', on='recording-id')
    for n,_ in enumerate(temp['mask']):
        if not np.isnan(temp['start'][n]):                        
            temp['mask'][n][round(temp['start'][n] / frame_length):round(temp['end'][n] / frame_length)] = temp['frames'][n]
    if len(wav_scp.index) > 1:
        wav_scp['mask'] = temp['mask'].drop_duplicates().reset_index(drop=True)
    else:
        wav_scp['mask'] = temp['mask']
    return wav_scp[['recording-id', 'mask']].set_index('recording-id')['mask'].to_dict()
def _segments_to_mask ( wav_scp : pd . DataFrame , segments : pd . DataFrame , frame_length : float = 0.01 ) -> Dict [ str , np . ndarray ] : wav_scp = wav_scp . copy ( ) wav_scp [ 'duration' ] = wav_scp [ 'extended filename' ] . apply ( lambda x : len ( wavfile . read ( x ) [ 1 ] ) / wavfile . read ( x ) [ 0 ] ) . astype ( float ) wav_scp [ 'mask' ] = round ( wav_scp [ 'duration' ] / frame_length ) . astype ( int ) . apply ( np . zeros ) segments = segments . copy ( ) segments [ 'frames' ] = ( round ( segments [ 'end' ] / frame_length ) . astype ( int ) - round ( segments [ 'start' ] / frame_length ) . astype ( int ) ) . apply ( np . ones ) temp = wav_scp . merge ( segments , how = 'left' , on = 'recording-id' ) for n , _ in enumerate ( temp [ 'mask' ] ) : if not np . isnan ( temp [ 'start' ] [ n ] ) : temp [ 'mask' ] [ n ] [ round ( temp [ 'start' ] [ n ] / frame_length ) : round ( temp [ 'end' ] [ n ] / frame_length ) ] = temp [ 'frames' ] [ n ] if len ( wav_scp . index ) > 1 : wav_scp [ 'mask' ] = temp [ 'mask' ] . drop_duplicates ( ) . reset_index ( drop = True ) else : wav_scp [ 'mask' ] = temp [ 'mask' ] return wav_scp [ [ 'recording-id' , 'mask' ] ] . set_index ( 'recording-id' ) [ 'mask' ] . to_dict ( )
Auxillary function used by score().
Auxillary function used by score () .
'''Auxillary function used by score(). Creates a dictionary of recording-ids to np.ndarrays,
    which are boolean masks indicating the presence of segments within a recording.

    Args:
        wav_scp: A pd.DataFrame containing wav file data in the following columns:
            [recording-id, extended filename]
        segments: A pd.DataFrame containing segments file data in the following columns:
            [utterance-id, recording-id, start, end]
        frame_length (optional): The length of the frames used for scoring in seconds. (Default: 0.01)

    Returns:
        A dictionary mapping recording-ids to np.ndarrays, which are boolean masks of the frames
        which makeup segments within a recording.

    Example:
        A 0.1 second clip with a segment starting at 0.03 and ending 0.07 would yeild a mask:
        [0, 0, 0, 1, 1, 1, 1, 0, 0, 0]
    ''' #segments['frames'] = segments.apply(lambda x: np.ones(math.ceil(x['end']/frame_length) - math.floor(x['start']/frame_length)), axis=1) #temp['mask'][n][math.floor(temp['start'][n] / frame_length):math.ceil(temp['end'][n] / frame_length)] = temp['frames'][n]
A dictionary mapping recording-ids to np.ndarrays, which are boolean masks of the frames
which makeup segments within a recording.
A dictionary mapping recording - ids to np . ndarrays which are boolean masks of the frames which makeup segments within a recording .
wav_scp
pd.DataFrame
A pd.DataFrame containing wav file data in the following columns:
[recording-id, extended filename]
A pd . DataFrame containing wav file data in the following columns : [ recording - id extended filename ]
segments
pd.DataFrame
A pd.DataFrame containing segments file data in the following columns:
[utterance-id, recording-id, start, end]
A pd . DataFrame containing segments file data in the following columns : [ utterance - id recording - id start end ]
frame_length
float
The length of the frames used for scoring in seconds.
The length of the frames used for scoring in seconds .
examples
None