def get_gmm(self): from sklearn.mixture import GMM as skGMM from gmmset import GMM as pyGMM if GMM == skGMM: print 'using GMM from sklearn' return GMM(self.nr_mixture) else: print 'using pyGMM' return GMM(nr_mixture=self.nr_mixture, nr_iteration=500, init_with_kmeans=0, concurrency=8, threshold=1e-15, verbosity=2)
def get_gmm(): # from sklearn.mixture import GMM as skGMM from sklearn.mixture import GaussianMixture as skGMM from gmmset import GMM as pyGMM if GMM == skGMM: print('using GMM from sklearn') return GMM(nr_mixture) else: print('using pyGMM') return GMM(nr_mixture=nr_mixture, nr_iteration=500, init_with_kmeans=0, concurrency=8, threshold=1e-15, verbosity=2)
def test_ubm_var_channel(): ubm = GMM.load('model/ubm.mixture-32.person-20.immature.model') train_duration = 8. nr_test = 5 test_duration = 3. audio_files = ['xinyu.vad.wav', 'wyx.wav'] X_train, y_train, X_test, y_test = [], [], [], [] for audio_file in audio_files: fs, signal = wavfile.read(audio_file) signal = monotize_signal(signal) train_len = int(fs * train_duration) test_len = int(fs * test_duration) X_train.append(mix_feature((fs, signal[:train_len]))) y_train.append(audio_file) for i in range(nr_test): start = random.randint(train_len, len(signal) - test_len) X_test.append(mix_feature((fs, signal[start:start + train_len]))) y_test.append(audio_file) gmmset = GMMSet(32, ubm=ubm) gmmset.fit(X_train, y_train) y_pred = gmmset.predict_with_reject(X_test) for i in xrange(len(y_pred)): print y_test[i], y_pred[i], '' if y_test[i] == y_pred[i] else 'wrong' for imposter_audio_file in map(lambda x: 'test-{}.wav'.format(x), range(5)): fs, signal = wavfile.read(imposter_audio_file) signal = monotize_signal(signal) imposter_x = mix_feature((fs, signal)) print gmmset.predict_one_with_rejection(imposter_x)
def test_ubm_var_channel(): ubm = GMM.load('model/ubm.mixture-32.person-20.immature.model') train_duration = 8. nr_test = 5 test_duration = 3. audio_files = ['xinyu.vad.wav', 'wyx.wav'] X_train, y_train, X_test, y_test = [], [], [], [] for audio_file in audio_files: fs, signal = wavfile.read(audio_file) signal = monotize_signal(signal) train_len = int(fs * train_duration) test_len = int(fs * test_duration) X_train.append(mix_feature((fs, signal[:train_len]))) y_train.append(audio_file) for i in range(nr_test): start = random.randint(train_len, len(signal) - test_len) X_test.append(mix_feature((fs, signal[start:start+train_len]))) y_test.append(audio_file) gmmset = GMMSet(32, ubm=ubm) gmmset.fit(X_train, y_train) y_pred = gmmset.predict_with_reject(X_test) for i in xrange(len(y_pred)): print y_test[i], y_pred[i], '' if y_test[i] == y_pred[i] else 'wrong' for imposter_audio_file in map( lambda x: 'test-{}.wav'.format(x), range(5)): fs, signal = wavfile.read(imposter_audio_file) signal = monotize_signal(signal) imposter_x = mix_feature((fs, signal)) print gmmset.predict_one_with_rejection(imposter_x)
def load(fname): """ load from a dumped model file""" with open(fname, 'r') as f: R = pickle.load(f) R.gmmset.after_pickle() ubm = GMM.load(ModelInterface.UBM_MODEL_FILE) R.gmmset.ubm = ubm return R
def main(): nr_person = 50 fpaths = get_training_data_fpaths() X_train, y_train, X_test, y_test = datautil.read_data(fpaths, nr_person) ubm = GMM.load('model/ubm-32.model') for x, y in zip(X_train, y_train): gmm = GMM(concurrency=8, threshold=0.01, nr_iteration=100, verbosity=1) gmm.fit(x, ubm=ubm) gmm.dump("model/" + y + ".32.model")
def _get_gmm_set(self): if os.path.isfile(self.ubm_model_file): try: from gmmset import GMMSetPyGMM if GMMSet is GMMSetPyGMM: return GMMSet(ubm=GMM.load(self.ubm_model_file)) except Exception as e: print "Warning: failed to import gmmset. You may forget to compile gmm:" print e print "Try running `make -C src/gmm` to compile gmm module." print "But gmm from sklearn will work as well! Using it now!" return GMMSet() return GMMSet()
def _get_gmm_set(self): if self.UBM_MODEL_FILE and os.path.isfile(self.UBM_MODEL_FILE): try: from gmmset import GMMSetPyGMM if GMMSet is GMMSetPyGMM: return GMMSet(ubm=GMM.load(self.UBM_MODEL_FILE)) except Exception as e: print("Warning: failed to import gmmset. You may forget to compile gmm:") print(e) print("Try running `make -C src/gmm` to compile gmm module.") print("But gmm from sklearn will work as well! Using it now!") return GMMSet() return GMMSet()
def _get_gmm_set(self): if os.path.isfile(self.UBM_MODEL_FILE): try: from gmmset import GMMSetPyGMM if GMMSet is GMMSetPyGMM: return GMMSet(ubm=GMM.load(self.UBM_MODEL_FILE)) except Exception as e: print "Warning: failed to import gmmset. You may forget to compile gmm:" print e print "Try running `make -C src/gmm` to compile gmm module." print "But gmm from sklearn will work as well! Using it now!" return GMMSet() return GMMSet()
def main(): nr_person = 50 fpaths = get_training_data_fpaths() X_train, y_train, X_test, y_test = datautil.read_data(fpaths, nr_person) ubm = GMM.load("model/ubm-32.model") for x, y in zip(X_train, y_train): gmm = GMM(concurrency=8, threshold=0.01, nr_iteration=100, verbosity=1) gmm.fit(x, ubm=ubm) gmm.dump("model/" + y + ".32.model")
def predict(self): """ return a label (name)""" try: ''' mfcc = MFCC.extract(self.FS, self.signal) lpc = LPC.extract(self.FS, self.signal) features = np.concatenate((mfcc, lpc), axis=1) ''' features = self.mix_feature() except Exception as e: print tb.format_exc() return None self.gmmset.ubm = GMM.load(self.ubm_model_file) #print 'The registered users are :', len(self.gmmset.y) #print self.gmmset.y #print [y for y in self.gmmset.y] return self.gmmset.predict_one_with_rejection(features)
for i in xrange(len(y_pred)): print y_test[i], y_pred[i], '' if y_test[i] == y_pred[i] else 'wrong' for imposter_audio_file in map(lambda x: 'test-{}.wav'.format(x), range(5)): fs, signal = wavfile.read(imposter_audio_file) signal = monotize_signal(signal) imposter_x = mix_feature((fs, signal)) print gmmset.predict_one_with_rejection(imposter_x) test_ubm_var_channel() import sys sys.exit(0) ubm = GMM.load('model/ubm.mixture-32.person-20.immature.model') gmm = GMM(32, verbosity=1) #audio_file = 'test-data/corpus.silence-removed/Style_Reading/f_001_03.wav' fs, signal = wavfile.read(audio_file) signal = monotize_signal(signal) X = mix_feature((fs, signal)) ubm = GMM.load('model/ubm.mixture-32.person-20.immature.model') gmm = GMM(32, verbosity=1) X = X[:1000] gmm.fit(X, ubm=ubm) gmm.dump('xinyu.model')
y_pred = gmmset.predict_with_reject(X_test) for i in xrange(len(y_pred)): print y_test[i], y_pred[i], '' if y_test[i] == y_pred[i] else 'wrong' for imposter_audio_file in map( lambda x: 'test-{}.wav'.format(x), range(5)): fs, signal = wavfile.read(imposter_audio_file) signal = monotize_signal(signal) imposter_x = mix_feature((fs, signal)) print gmmset.predict_one_with_rejection(imposter_x) test_ubm_var_channel() import sys sys.exit(0) ubm = GMM.load('model/ubm.mixture-32.person-20.immature.model') gmm = GMM(32, verbosity=1) #audio_file = 'test-data/corpus.silence-removed/Style_Reading/f_001_03.wav' fs, signal = wavfile.read(audio_file) signal = monotize_signal(signal) X = mix_feature((fs, signal)) ubm = GMM.load('model/ubm.mixture-32.person-20.immature.model') gmm = GMM(32, verbosity=1) X = X[:1000] gmm.fit(X, ubm=ubm) gmm.dump('xinyu.model')