freqanalysis.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:audioanalysis 作者: jpalpant 项目源码 文件源码
def get_data_sample(self, idx):
        """Get a sample from the spectrogram and the corresponding class

        Inputs:
            idx: an ndarray of integer indices

        Returns:
            data: data is a 
                (1,1,img_rows,img_cols) slice from Sxx and classification is
                the corresponding integer class from
                self.active_song.classification

        If idx exceeds the dimensions of the data, throws IndexError
        If there is not a processed, active song, throws TypeError
        """

        img_rows = self.params.get('img_rows', self.Sxx.shape[0])
        img_cols = self.params.get('img_cols', 1)

        if self.Sxx is None or self.active_song.classification is None:
            raise TypeError('No active song from which to get data')

        if np.amax(idx) > self.Sxx.shape[1]:
            raise IndexError('Data index of sample out of bounds, only {0} '
                    'samples in the dataset'.format(self.Sxx.shape[1] - img_cols))

        if np.amin(idx) < 0:
            raise IndexError('Data index of sample out of bounds, '
                    'negative index requested')

        # index out the data
        max_idx = (self.Sxx.shape[1] - 1)

        data_slices = [self.Sxx[0:img_rows, np.minimum(
            max_idx, idx + i)].T.reshape(idx.size, 1, img_rows) for i in range(img_cols)]
        data = np.stack(data_slices, axis=-1)

        # scale the input
        data = np.log10(data)
        data -= np.amin(data)
        data /= np.amax(data)

        return data
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号