-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathANN Model.py
89 lines (55 loc) · 1.75 KB
/
ANN Model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# Importing the Libraries
import json
import numpy as np
import pandas as pd
'''
# data load
# data split
# artitecture
# train
# eval
#predication
'''
# Loading Data
def Load_Data(Path):
with open(Path,"r") as fp:
data=json.loads(fp.read())
return data
data=Load_Data(r'data_10.json')
X=data['mfcc']
Y=data['labels']
X=np.array(X)
Y=np.array(Y)
print(len(X))
print(len(Y))
print(X.shape)
print(Y.shape)
Y=Y.reshape((999,1))
# Splitting the Data
from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test=train_test_split(X,Y,test_size=20,random_state=10)
import tensorflow.keras as keras
classifier=keras.Sequential()
classifier.add(keras.layers.Flatten(input_shape=(X.shape[1],X.shape[2])))
classifier.add(keras.layers.Dense(512,activation='relu',kernel_regularizer=keras.regularizers.l2(0.001)))
classifier.add(keras.layers.Dense(256,activation='relu',kernel_regularizer=keras.regularizers.l2(0.001)))
classifier.add(keras.layers.Dense(64,activation='relu',kernel_regularizer=keras.regularizers.l2(0.001)))
classifier.add(keras.layers.Dense(10,activation='softmax'))
optimizer=keras.optimizers.Adam(learning_rate=0.001)
classifier.compile(optimizer=optimizer,loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
his=classifier.fit(x_train,y_train,validation_data=(x_test,y_test),
epochs=40,batch_size=32)
classifier.summary()
his.history.keys()
# Acurracy
import matplotlib.pyplot as plt
plt.plot(his.epoch,his.history['accuracy'],label='acc')
plt.plot(his.epoch,his.history['val_accuracy'],label='val')
plt.legend()
plt.show()
# Validation Loss
plt.plot(his.epoch,his.history['loss'],label='acc')
plt.plot(his.epoch,his.history['val_loss'],label='val')
plt.legend()
plt.show()