diff --git a/test.py b/test.py index 1a8475d..9ff7002 100644 --- a/test.py +++ b/test.py @@ -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) \ No newline at end of file + check_preds(X_test, y_test) \ No newline at end of file diff --git a/utils/model.py b/utils/model.py index adf298f..27e8b9e 100644 --- a/utils/model.py +++ b/utils/model.py @@ -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 diff --git a/utils/wav2mfcc.py b/utils/wav2mfcc.py index 01ff482..9e6b5df 100644 --- a/utils/wav2mfcc.py +++ b/utils/wav2mfcc.py @@ -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) @@ -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()