add prediction and change training and test
authorMart Lubbers <mart@martlubbers.net>
Tue, 21 Mar 2017 19:15:57 +0000 (20:15 +0100)
committerMart Lubbers <mart@martlubbers.net>
Tue, 21 Mar 2017 19:15:57 +0000 (20:15 +0100)
predict.py [new file with mode: 0644]
preprocess.sh
test.py
train.py

diff --git a/predict.py b/predict.py
new file mode 100644 (file)
index 0000000..f2adb8e
--- /dev/null
@@ -0,0 +1,17 @@
+import numpy as np
+import sys
+from keras.models import model_from_json
+
+with open('model.json', 'r') as f:
+    json = f.read()
+
+model = model_from_json(json)
+model.load_weights('./model.hdf5')
+model.compile(
+    loss='binary_crossentropy',
+    optimizer='rmsprop',
+    metrics=['accuracy'])
+
+dat = np.genfromtxt(sys.stdin.buffer, dtype=float, delimiter='\t')
+for i in model.predict(dat, batch_size=32, verbose=0):
+    print(i[0])
index 6543202..499b706 100644 (file)
@@ -5,25 +5,25 @@ MAXPROCS=4
 FREQUENCY=44100
 #FREQUENCY=22050
 
-rm -rf wav mfcc
-mkdir -p wav mfcc
-i=0
-for f in orig/*.flac; do
-       while [ $(jobs -p | wc -l) -ge $MAXPROCS ]; do sleep 1; done
-       
-       echo $f
-       BN="$(echo $f | grep -Po "(?<=/[0-9][0-9]_-_).*(?=\.flac)")"
-       NUM="$(printf '%02d' "$i")"
-       WAV="wav/$NUM.wav"
-       MFCC="mfcc/$NUM.mfcc"
-
-       (       echo "Processing $f" &&
-               sox "$f" -V1 -c 1 -r $FREQUENCY $WAV &&
-               python mfcc.py < "$WAV" > "$MFCC"
-       ) &
-       i=$((i+1))
-done
-wait
+#rm -rf wav mfcc
+#mkdir -p wav mfcc
+#i=0
+#for f in orig/*.flac; do
+#      while [ $(jobs -p | wc -l) -ge $MAXPROCS ]; do sleep 1; done
+#      
+#      echo $f
+#      BN="$(echo $f | grep -Po "(?<=/[0-9][0-9]_-_).*(?=\.flac)")"
+#      NUM="$(printf '%02d' "$i")"
+#      WAV="wav/$NUM.wav"
+#      MFCC="mfcc/$NUM.mfcc"
+#
+#      (       echo "Processing $f" &&
+#              sox "$f" -V1 -c 1 -r $FREQUENCY $WAV &&
+#              python mfcc.py < "$WAV" > "$MFCC"
+#      ) &
+#      i=$((i+1))
+#done
+#wait
 python segment.py
 python train.py
 python test.py
diff --git a/test.py b/test.py
index 72a787c..7378596 100644 (file)
--- a/test.py
+++ b/test.py
@@ -13,7 +13,7 @@ model.compile(
 
 model.summary()
 
-dat = np.genfromtxt('test.txt', dtype=float, delimiter='\t')[:, range(1, 14)]
-lab = np.genfromtxt('test.txt', dtype=int, delimiter='\t')[:, 0]
+dat = np.genfromtxt('test.txt', dtype=float, delimiter='\t', usecols=range(1, 14))
+lab = np.genfromtxt('test.txt', dtype=int, delimiter='\t', usecols=[0])
 
 print(model.evaluate(dat, lab, batch_size=32))
index a4ecbbc..2f6bc91 100644 (file)
--- a/train.py
+++ b/train.py
@@ -4,7 +4,7 @@ from keras.layers import Dense, Dropout  # , Activation
 
 model = Sequential()
 
-model.add(Dense(26, input_shape=(13,), activation='relu'))
+model.add(Dense(2000, input_shape=(13,), activation='relu'))
 model.add(Dense(1, activation='sigmoid'))
 
 model.compile(
@@ -14,8 +14,8 @@ model.compile(
 
 model.summary()
 
-dat = np.genfromtxt('train.txt', dtype=float, delimiter='\t')[:, range(1, 14)]
-lab = np.genfromtxt('train.txt', dtype=int, delimiter='\t')[:, 0]
+dat = np.genfromtxt('train.txt', dtype=float, delimiter='\t', usecols=range(1, 14))
+lab = np.genfromtxt('train.txt', dtype=int, delimiter='\t', usecols=[0])
 
 model.fit(dat, lab, epochs=10, batch_size=32)