## Conv1D based model
model = tf.keras.models.Sequential([
tf.keras.layers.Conv1D(filters=16, kernel_size=3, activation='relu',
input_shape=(TIMESERIES_LEN, 3)),
tf.keras.layers.Conv1D(filters=8, kernel_size=3, activation='relu'),
tf.keras.layers.Dropout(0.5),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(64, activation='relu'),
tf.keras.layers.Dense(4, activation='softmax')
])
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
model.fit(x_train, y_train, epochs=1000)
model.summary()
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
Y_pred = model.predict(x_test)
y_pred = np.argmax(Y_pred, axis=1)
confusion_matrix = tf.math.confusion_matrix(y_test, y_pred)
plt.figure()
sns.heatmap(confusion_matrix,
plt.tight_layout()
plt.ylabel('True label')
plt.xlabel('Predicted label')
plt.show()
model.save('model_car_sts.h5')
UM3053 - Rev 1
annot=True,
xticklabels=Y_LABELS,
yticklabels=Y_LABELS,
cmap=plt.cm.Blues,
fmt='d', cbar=False)
Google Colab code for the neural network training
UM3053
page 32/39
Need help?
Do you have a question about the AEKD-AICAR1 and is the answer not in the manual?
Questions and answers