Commit
·
a83fb6e
1
Parent(s):
9c960c7
Upload main.py
Browse files
main.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import tensorflow as tf
|
3 |
+
from tensorflow import keras
|
4 |
+
from tensorflow.keras import layers
|
5 |
+
|
6 |
+
def model(input_shape):
|
7 |
+
|
8 |
+
x_input = layers.Input(shape = input_shape)
|
9 |
+
|
10 |
+
x = layers.Conv1D(196, kernel_size=15, strides=4)(x_input)
|
11 |
+
x = layers.BatchNormalization()(x)
|
12 |
+
x = layers.Activation('relu')(x)
|
13 |
+
x = layers.Dropout(0.8)(x)
|
14 |
+
|
15 |
+
x = layers.GRU(units = 128, return_sequences = True)(x)
|
16 |
+
x = layers.Dropout(0.8)(x)
|
17 |
+
x = layers.BatchNormalization()(x)
|
18 |
+
|
19 |
+
x = layers.GRU(units = 128, return_sequences = True)(x)
|
20 |
+
x = layers.Dropout(0.8)(x)
|
21 |
+
x = layers.BatchNormalization()(x)
|
22 |
+
x = layers.Dropout(0.8)(x)
|
23 |
+
|
24 |
+
x = layers.TimeDistributed(layers.Dense(1, activation = "sigmoid"))(x)
|
25 |
+
model = keras.Model(inputs = x_input, outputs = x)
|
26 |
+
|
27 |
+
return model
|
28 |
+
|
29 |
+
|
30 |
+
#model = model(input_shape = (Tx, n_freq))
|
31 |
+
model = model(input_shape = (5511, 101))
|
32 |
+
model.summary()
|
33 |
+
|
34 |
+
opt = keras.optimizers.Adam(lr=0.0001, beta_1=0.9, beta_2=0.999, decay=0.01)
|
35 |
+
model.compile(loss='binary_crossentropy', optimizer=opt, metrics=["accuracy"])
|
36 |
+
|
37 |
+
X = np.load("./Data/XY_train/X.npy")
|
38 |
+
Y = np.load("./Data/XY_train/Y.npy")
|
39 |
+
|
40 |
+
X_dev = np.load("./Data/XY_dev/X_dev.npy")
|
41 |
+
Y_dev = np.load("./Data/XY_dev/Y_dev.npy")
|
42 |
+
|
43 |
+
model.fit(X, Y, batch_size = 64, epochs=20000)
|
44 |
+
|
45 |
+
# save model
|
46 |
+
model.save('my_model.h5') # creates a HDF5 file 'my_model.h5'
|
47 |
+
# del model # deletes the existing model
|
48 |
+
|
49 |
+
# returns a compiled model
|
50 |
+
# identical to the previous one
|
51 |
+
# model = load_model('my_model.h5')
|