msaf/algorithms/fmc2d/segmenter.py
def feat_segments_to_2dfmc_max(feat_segments, offset=4):
    """From a list of feature segments, return a list of 2D-Fourier Magnitude
    Coefs using the maximum segment size as main size and zero pad the rest.

    Parameters
    ----------
    feat_segments: list
        List of segments, one for each boundary interval.
    offset: int >= 0
        Number of frames to ignore from beginning and end of each segment.

    Returns
    -------
    fmcs: np.ndarray
        Tensor containing the 2D-FMC matrices, one matrix per segment.
    """
    if len(feat_segments) == 0:
        return []

    # Get maximum segment size
    max_len = max([feat_segment.shape[0] for feat_segment in feat_segments])

    fmcs = []
    for feat_segment in feat_segments:
        # Zero pad if needed
        X = np.zeros((max_len, feat_segment.shape[1]))

        # Remove a set of frames in the beginning an end of the segment
        if feat_segment.shape[0] <= offset or offset == 0:
            X[:feat_segment.shape[0], :] = feat_segment
        else:
            X[:feat_segment.shape[0] - offset, :] = \
                feat_segment[offset // 2:-offset // 2, :]

        # Compute the 2D-FMC
        try:
            fmcs.append(utils2d.compute_ffmc2d(X))
        except:
            logging.warning("Couldn't compute the 2D Fourier Transform")
            fmcs.append(np.zeros((X.shape[0] * X.shape[1]) // 2 + 1))

        # Normalize
        # fmcs[-1] = fmcs[-1] / float(fmcs[-1].max())

    return np.asarray(fmcs)
def feat_segments_to_2dfmc_max(feat_segments, offset=4):
    if len(feat_segments) == 0:
        return []

    # Get maximum segment size
    max_len = max([feat_segment.shape[0] for feat_segment in feat_segments])

    fmcs = []
    for feat_segment in feat_segments:
        # Zero pad if needed
        X = np.zeros((max_len, feat_segment.shape[1]))

        # Remove a set of frames in the beginning an end of the segment
        if feat_segment.shape[0] <= offset or offset == 0:
            X[:feat_segment.shape[0], :] = feat_segment
        else:
            X[:feat_segment.shape[0] - offset, :] = \
                feat_segment[offset // 2:-offset // 2, :]

        # Compute the 2D-FMC
        try:
            fmcs.append(utils2d.compute_ffmc2d(X))
        except:
            logging.warning("Couldn't compute the 2D Fourier Transform")
            fmcs.append(np.zeros((X.shape[0] * X.shape[1]) // 2 + 1))

        # Normalize
        # fmcs[-1] = fmcs[-1] / float(fmcs[-1].max())

    return np.asarray(fmcs)
def feat_segments_to_2dfmc_max ( feat_segments , offset = 4 ) : if len ( feat_segments ) == 0 : return [ ] # Get maximum segment size max_len = max ( [ feat_segment . shape [ 0 ] for feat_segment in feat_segments ] ) fmcs = [ ] for feat_segment in feat_segments : # Zero pad if needed X = np . zeros ( ( max_len , feat_segment . shape [ 1 ] ) ) # Remove a set of frames in the beginning an end of the segment if feat_segment . shape [ 0 ] <= offset or offset == 0 : X [ : feat_segment . shape [ 0 ] , : ] = feat_segment else : X [ : feat_segment . shape [ 0 ] - offset , : ] = feat_segment [ offset // 2 : - offset // 2 , : ] # Compute the 2D-FMC try : fmcs . append ( utils2d . compute_ffmc2d ( X ) ) except : logging . warning ( "Couldn't compute the 2D Fourier Transform" ) fmcs . append ( np . zeros ( ( X . shape [ 0 ] * X . shape [ 1 ] ) // 2 + 1 ) ) # Normalize # fmcs[-1] = fmcs[-1] / float(fmcs[-1].max()) return np . asarray ( fmcs )
From a list of feature segments, return a list of 2D-Fourier Magnitude
    Coefs using the maximum segment size as main size and zero pad the rest.

    Parameters
    ----------
    feat_segments: list
        List of segments, one for each boundary interval.
    offset: int >= 0
        Number of frames to ignore from beginning and end of each segment.

    Returns
    -------
    fmcs: np.ndarray
        Tensor containing the 2D-FMC matrices, one matrix per segment.
From a list of feature segments return a list of 2D - Fourier Magnitude Coefs using the maximum segment size as main size and zero pad the rest .