update
authorMart Lubbers <mart@martlubbers.net>
Sun, 30 Apr 2017 17:24:43 +0000 (19:24 +0200)
committerMart Lubbers <mart@martlubbers.net>
Sun, 30 Apr 2017 17:24:43 +0000 (19:24 +0200)
.gitignore
experiments.py

index 2e8dbe8..2146a79 100644 (file)
@@ -8,3 +8,5 @@ model.*
 model.*
 test.txt
 train.txt
+*.hdf5
+*.json
index 989643e..699c68c 100644 (file)
@@ -1,18 +1,17 @@
-import sys
 import pympi
-import random
 import glob
 import re
 import os
 
 # mfcc
-from python_speech_features import mfcc, fbank, logfbank
+from python_speech_features import mfcc, logfbank
 import scipy.io.wavfile as wav
 import numpy as np
 
-#keras
+# keras
 from keras.models import Sequential
 from keras.layers import Dense, Dropout  # , Activation
+from keras import backend
 
 # Testset ratio
 testset = 0.10
@@ -97,6 +96,7 @@ def run(typ, winlen, winstep, modelfun, modelname):
                                verbose=verbosity)
     print('{}\t{}\t{}\t{}\t{}\n'.format(
         winlen, winstep, modelname, loss, acc))
+    return model
 
 def simplemodel(d):
     model = Sequential()
@@ -122,6 +122,11 @@ def bottlemodel(d):
 
 if __name__ == '__main__':
     print('winlen\twinstep\tmodel\tloss\taccuracy\n')
-    for winlen, winstep in ((0.025, 0.01), (0.1, 0.04), (0.2, 0.08)):
-        for name, model in (('simple', simplemodel), ('bottle', bottlemodel)):
-            run('mfcc', winlen, winstep, model, name)
+    with backend.get_session():
+        for winlen, winstep in ((0.025, 0.01), (0.1, 0.04), (0.2, 0.08)):
+            for name, model in (('simple', simplemodel), ('bottle', bottlemodel)):
+                m = run('mfcc', winlen, winstep, model, name)
+                fproot = 'model_{}_{}_{}.json'.format(winlen, winstep, name)
+                with open('{}.json'.format(fproot), 'w') as f:
+                    f.write(m.to_json())
+                m.save_weights('{}.hdf5'.format(fproot))