From: Mart Lubbers Date: Tue, 21 Mar 2017 19:15:57 +0000 (+0100) Subject: add prediction and change training and test X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=5f9dd7efffc88598b99d6ddeada4c08dd9a4d4d3;p=asr1617data.git add prediction and change training and test --- diff --git a/predict.py b/predict.py new file mode 100644 index 0000000..f2adb8e --- /dev/null +++ b/predict.py @@ -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]) diff --git a/preprocess.sh b/preprocess.sh index 6543202..499b706 100644 --- a/preprocess.sh +++ b/preprocess.sh @@ -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 --- 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)) diff --git a/train.py b/train.py index a4ecbbc..2f6bc91 100644 --- 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)