使用 MFCC 特征作为输入数据((20X56829)的 Numpy 数组),通过应用 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:
我的初始化有什么问题吗?