Python:MFCC特性中的HMM实现

2024-09-28 16:57:45 发布

您现在位置:Python中文网/ 问答频道 /正文

使用MFCC特性作为输入数据(Numpy数组为(20X56829)),通过应用HMM尝试从HMM的解码状态创建音频词汇表。在MFCC特性中我有10个扬声器。我需要每个发言者50个州。所以我使用了N=500个状态,它抛出了内存错误,但它在N=100个状态下工作得很好。在

代码如下:

import numpy as np
from hmmlearn import hmm
import librosa

def getMFCC(episode):

    filename = getPathToGroundtruth(episode)

    y, sr = librosa.load(filename)  # Y gives 

    data = librosa.feature.mfcc(y=y, sr=sr)

    return data

def hmm_init(n,data):  #n = states d = no of feautures

    states =[]

    model = hmm.GaussianHMM(n_components=N, covariance_type="full")

    model.transmat_ = np.ones((N, N)) / N

    model.startprob_ = np.ones(N) / N

    fit = model.fit(data.T)

    z=fit.decode(data.T,algorithm='viterbi')[1]

    states.append(z)

    return states

data_m = getMFCC(1)  # Provides MFCC features of numpy array [20 X 56829]

N = 500

D= len(data)

states = hmm_init(N,data)

In [23]: run Final_hmm.py
---------------------------------------------------------------------------
MemoryError                               Traceback (most recent call last)
/home/elancheliyan/Final_hmm.py in <module>()
     73 D= len(data)
     74 
---> 75 states = hmm_init(N,data)
     76 states.dump("states")
     77 

/home/elancheliyan/Final_hmm.py in hmm_init(n, data)
     57     model.startprob_ = np.ones(N) / N
     58 
---> 59     fit = model.fit(data.T)
     60 
     61     z=fit.decode(data.T,algorithm='viterbi')[1]

/cal/homes/elancheliyan/.local/lib/python3.5/site-packages/hmmlearn-0.2.1-py3.5-linux-x86_64.egg/hmmlearn/base.py in fit(self, X, lengths)
    434                 self._accumulate_sufficient_statistics(
    435                     stats, X[i:j], framelogprob, posteriors, fwdlattice,
--> 436                     bwdlattice)
    437 
    438             # XXX must be before convergence check, because otherwise

/cal/homes/elancheliyan/.local/lib/python3.5/site-packages/hmmlearn-0.2.1-py3.5-linux-x86_64.egg/hmmlearn/hmm.py in _accumulate_sufficient_statistics(self, stats, obs, framelogprob, posteriors, fwdlattice, bwdlattice)
    221                                           posteriors, fwdlattice, bwdlattice):
    222         super(GaussianHMM, self)._accumulate_sufficient_statistics(
--> 223             stats, obs, framelogprob, posteriors, fwdlattice, bwdlattice)
    224 
    225         if 'm' in self.params or 'c' in self.params:

/cal/homes/elancheliyan/.local/lib/python3.5/site-packages/hmmlearn-0.2.1-py3.5-linux-x86_64.egg/hmmlearn/base.py in _accumulate_sufficient_statistics(self, stats, X, framelogprob, posteriors, fwdlattice, bwdlattice)
    620                 return
    621 
--> 622             lneta = np.zeros((n_samples - 1, n_components, n_components))
    623             _hmmc._compute_lneta(n_samples, n_components, fwdlattice,
    624                                  log_mask_zero(self.transmat_),

MemoryError:

我的初始化有什么问题吗?在


Tags: inpyselfdatamodelinitnpfit