import tensorflow as tf
import matplotlib.pyplot as plt
training = ...
validation = ...
model = tf.keras.models.Sequential([
tf.keras.layers.Conv1D(32, 4, input_shape=(200, 4), activation='relu'),
tf.keras.layers.MaxPool1D(2),
tf.keras.layers.Conv1D(64, 4, activation='relu'),
tf.keras.layers.MaxPool1D(2),
tf.keras.layers.Conv1D(128, 4, activation='relu'),
tf.keras.layers.MaxPool1D(2),
tf.keras.layers.Flatten(),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Dense(512, activation='relu'),
tf.keras.layers.Dense(1024, activation='relu'),
tf.keras.layers.Dense(1, activation='sigmoid'),
])
model.build()
model.summary()
model.compile(loss='binary_crossentropy', optimizer=tf.keras.optimizers.Adam(learning_rate=0.0001), metrics=['acc'])
his = model.fit(training['x'], training['y'], epochs=10, validation_data=(validation['x'], validation['y']))
model.save('../output/model-data/model.h5')
plt.plot(his.history['acc'], label = 'Training')
plt.plot(his.history['val_acc'], label = 'Validation')
plt.legend()
plt.show()
test_loss, test_acc = model.evaluate(test_x, test_y, verbose=2)
model = tf.keras.models.load_model('../output/model-data/model.h5')
probability_model = tf.keras.Sequential([model, tf.keras.layers.Softmax()])
predictions = probability_model.predict(np.asarray([the_data]))