Beispiel #1
0
'''

classList = labels.tolist()

classDic = dict([(c, n) for n, c in enumerate(classList)])
classDic  # In[]

#y_test= np.array([classDic[x] for x in y_testREAL])

y_pred = np.array([classDic[x] for x in yL])

cm_testREAL1 = confusion_matrix(y_testREAL1, y_pred)

#set(y_test)

audioUtils.plot_confusion_matrix(cm_testREAL1, classList)  #, normalize=True)

# In[]
yPredProb = m.predict(X_testREAL1)

y_pred = yPredProb.argmax(axis=1)

cm_testREAL1 = confusion_matrix(y_testREAL1, y_pred)

#set(y_test)

audioUtils.plot_confusion_matrix(
    cm_testREAL1, classList,
    title='Confusion matrix: y_testREAL1')  #, normalize=True)

# In[]
Beispiel #2
0
rec = recall_score(y_test, y_pred, average='micro')

#F1 - high if both recall and precision are high.
from sklearn.metrics import f1_score
f1 = f1_score(y_test, y_pred, average='micro')

print("Precision:\t", round(prec, 3))
print("Recall:\t\t", round(rec, 3))
print("F1:\t\t", round(f1, 3))

# Confusion Matrix
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred)
import audioUtils
audioUtils.plot_confusion_matrix(cm,
                                 categories,
                                 normalize=False,
                                 save_path=save_dir)

# SAVE MODEL SUMMARY and METRICS TO FILE
f = open(save_dir + "Metrics.txt", "a")

stringlist = []
model.summary(print_fn=lambda x: stringlist.append(x))
short_model_summary = "\n".join(stringlist)
f.write(short_model_summary + "\n\n")

f.write('Train loss:\t' + str(round(train_loss, 3)) + "\n")
f.write('Train accuracy:\t' + str((round(1 - train_error, 3))) + "\n")
f.write('Val loss:\t' + str(round(val_loss, 3)) + "\n")
f.write('Val accuracy:\t' + str((round(1 - val_error, 3))) + "\n")
f.write('Test loss:\t' + str(round(test_loss, 3)) + "\n")
Beispiel #3
0
         'bed', 'bird', 'cat', 'dog', 'happy', 'house', 
         'marvin', 'sheila', 'tree', 'wow']


# In[ ]:


#20cmd
classes=['unknown', 'nine', 'yes',  'no', 'up', 'down', 'left', 'right', 'on', 'off', 'stop', 'go',
         'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven',  'eight']


# In[ ]:


audioUtils.plot_confusion_matrix(cmP,classes, normalize=True)
audioUtils.plot_confusion_matrix(cmFN,classes, normalize=True)


# In[ ]:





# In[ ]:




Beispiel #4
0
def get_confusion_matrix(y_test, y_pred, keywords):
    cm = confusion_matrix(y_test, np.argmax(y_pred, 1))
    keywordList = list(keywords.keys())
    audioUtils.plot_confusion_matrix(cm, keywordList, normalize=True)
Beispiel #5
0
#35word, v1
#classes=['nine', 'yes',  'no', 'up', 'down', 'left', 'right', 'on', 'off', 'stop', 'go',
#         'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven',  'eight',
#         'bed', 'bird', 'cat', 'dog', 'happy', 'house',
#         'marvin', 'sheila', 'tree', 'wow']

# In[38]:

#20cmd
#classes=['unknown', 'nine', 'yes',  'no', 'up', 'down', 'left', 'right', 'on', 'off', 'stop', 'go',
#         'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven',  'eight']

# In[39]:

audioUtils.plot_confusion_matrix(cm, classes, normalize=False)

# In[39]:

# In[40]:

import pandas as pd
import kapre
[tf.__version__, kapre.__version__, pd.__version__, librosa.__version__]

# # Save model to .pb

# In[48]:

#model = SpeechModels.AttRNNSpeechModel(nCategs, samplingrate = sr, inputLength = None)#, rnn_func=L.LSTM)
#model.load_weights('model-attRNN.h5')