Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for changes to keras and tensorflow #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions test.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import keras
from sklearn.metrics import classification_report
from utils import wav2mfcc, model, get_data
from keras.utils import to_categorical
import numpy as np
import tensorflow as tf

def check_preds(X, y):

trained_model = keras.models.load_model('trained_model.h5')
predictions = trained_model.predict_classes(X)
predictions = trained_model.predict(X)
classes_x = np.argmax(predictions, axis=1)
print(classification_report(y, tf.keras.utils.to_categorical(classes_x)))

print(classification_report(y, to_categorical(predictions)))

if __name__ == '__main__':
_, X_test, _, y_test, _ = get_data.get_all()

# if __name__ == '__main__':
# _, X_test, _, y_test, _ = get_data.get_all()
#
# check_preds(X_test, y_test)
check_preds(X_test, y_test)
2 changes: 1 addition & 1 deletion utils/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_cnn_model(input_shape, num_classes):
model.add(BatchNormalization())
model.add(Dropout(0.4))
model.add(Dense(num_classes, activation='softmax'))
model.compile(loss=keras.losses.categorical_crossentropy, optimizer=keras.optimizers.Adadelta(), metrics=['accuracy'])
model.compile(loss="categorical_crossentropy", optimizer='Adadelta', metrics=['accuracy'])

return model

Expand Down
4 changes: 2 additions & 2 deletions utils/wav2mfcc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import librosa
import os
from keras.utils import to_categorical
import tensorflow as tf

def wav2mfcc(file_path, max_pad_len=20):
wave, sr = librosa.load(file_path, mono=True, sr=None)
Expand All @@ -25,7 +25,7 @@ def get_data():
label = f.split('_')[0]
labels.append(label)

return np.asarray(mfccs), to_categorical(labels)
return np.asarray(mfccs), tf.keras.utils.to_categorical(labels)

# if __name__ == '__main__':
# mfccs, labels = get_data()
Expand Down