File size: 1,492 Bytes
a83fb6e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import numpy as np
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers

def model(input_shape):

    x_input = layers.Input(shape = input_shape)

    x = layers.Conv1D(196, kernel_size=15, strides=4)(x_input)
    x = layers.BatchNormalization()(x)
    x = layers.Activation('relu')(x)
    x = layers.Dropout(0.8)(x)

    x = layers.GRU(units = 128, return_sequences = True)(x)
    x = layers.Dropout(0.8)(x)
    x = layers.BatchNormalization()(x)
    
    x = layers.GRU(units = 128, return_sequences = True)(x)
    x = layers.Dropout(0.8)(x)
    x = layers.BatchNormalization()(x)
    x = layers.Dropout(0.8)(x)
    
    x = layers.TimeDistributed(layers.Dense(1, activation = "sigmoid"))(x)
    model = keras.Model(inputs = x_input, outputs = x)
    
    return model  


#model = model(input_shape = (Tx, n_freq))
model = model(input_shape = (5511, 101))
model.summary()

opt = keras.optimizers.Adam(lr=0.0001, beta_1=0.9, beta_2=0.999, decay=0.01)
model.compile(loss='binary_crossentropy', optimizer=opt, metrics=["accuracy"])

X = np.load("./Data/XY_train/X.npy")
Y = np.load("./Data/XY_train/Y.npy")

X_dev = np.load("./Data/XY_dev/X_dev.npy")
Y_dev = np.load("./Data/XY_dev/Y_dev.npy")

model.fit(X, Y, batch_size = 64, epochs=20000)

# save model
model.save('my_model.h5')  # creates a HDF5 file 'my_model.h5'
# del model  # deletes the existing model

# returns a compiled model
# identical to the previous one
# model = load_model('my_model.h5')