Here I have a code to classify the EMG signal for the 10 Different types of gestures, but when i run the model it takes about 90 hours to train the model which is too much
# Train and test the model
#Set names for targets (gesture labels)
LABELS = ["CLO",
"IND",
"LIT",
"MID",
"RIN",
"THI",
"THL",
"THM",
"THR",
"THU"]
#Create callback for early stopping, initialize optimizer
callbacks_list = [keras.callbacks.EarlyStopping(monitor='accuracy', patience=10)]
opt = Adagrad(learning_rate=0.01)
#Create, compile, train, and test CNN for each subject individually
# Create/build CNN architecture
EMG_CNN = Sequential()
EMG_CNN.add(Reshape((WINDOW_SIZE, INPUT_CHANN_COUNT), input_shape=(250,2)))
EMG_CNN.add(Conv1D(filters=CNN_FILTER_COUNT, kernel_size=KERNEL_SIZE, activation='relu', strides=STRIDE_LENGTH, input_shape=(WINDOW_SIZE,INPUT_CHANN_COUNT))) #Conv
EMG_CNN.add(Conv1D(filters=CNN_FILTER_COUNT, kernel_size=KERNEL_SIZE, activation='relu', strides=STRIDE_LENGTH)) #Conv
EMG_CNN.add(MaxPool1D(pool_size=8, strides=8)) #Max Pooling
EMG_CNN.add(Conv1D(filters=CNN_FILTER_COUNT, kernel_size=KERNEL_SIZE, activation='relu', strides=STRIDE_LENGTH)) #Conv
EMG_CNN.add(Conv1D(filters=CNN_FILTER_COUNT, kernel_size=KERNEL_SIZE, activation='relu', strides=STRIDE_LENGTH)) #Conv
EMG_CNN.add(GlobalAveragePooling1D()) #Global Avg. Pooling
EMG_CNN.add(Dropout(DROPOUT_RATE)) #Dropout
EMG_CNN.add(Dense(OUTPUT_CLASSES_COUNT, activation='softmax')) #Fully Connected
# Compile CNN
EMG_CNN.compile(loss='categorical_crossentropy',
optimizer=opt,
metrics=['accuracy'])
print(EMG_CNN.summary())
#----Train CNN----#
print("Training EMG_CNN on data...")
history = EMG_CNN.fit(x_train,
y_train,
batch_size=32,
epochs=50,
callbacks=callbacks_list,
validation_split=0.2,
verbose=1)
#Visualize training and validation curves, confusion matrix
print("\n--- Learning curve of model training ---\n")
#Accuracy plot
plt.figure(figsize=(6, 4))
plt.plot(history.history['accuracy'], "g--", label="Accuracy of training data")
plt.plot(history.history['val_accuracy'], "g", label="Accuracy of validation data")
plt.title('Model Accuracy')
plt.ylabel('Accuracy')
plt.xlabel('Training Epoch')
plt.ylim(0)
plt.legend()
#Loss plot
plt.figure(figsize=(6, 4))
plt.plot(history.history['loss'], "r--", label="Loss of training data")
plt.plot(history.history['val_loss'], "r", label="Loss of validation data")
plt.title('Model Loss')
plt.ylabel('Loss')
plt.xlabel('Training Epoch')
plt.ylim(0)
plt.legend()
plt.show()
#Evaluate the accuracy and loss value on test data
print("\n--- Check against test data ---\n")
score = EMG_CNN.evaluate(X_test, Y_test, verbose=1)
print("\nAccuracy on test data: %0.2f" % score[1])
print("\nLoss on test data: %0.2f" % score[0])
#Display the confusion matrix for test data
print("\n--- Confusion matrix for test data ---\n")
y_pred_test = EMG_CNN.predict(X_test)
# Take the class with the highest probability from the test predictions
max_y_pred_test = np.argmax(y_pred_test, axis=1)
max_y_test = np.argmax(Y_test, axis=1)
show_confusion_matrix(max_y_test, max_y_pred_test)
#Display classification report (which includes F1, precision, recall) for the test data
print("\n--- Classification report for test data ---\n")
print(classification_report(max_y_test, max_y_pred_test))
I have 10 subject datasets to train the model however, I applied deep learning to each of the 10 subjects individually. It took me 3-5 days of training and I got about 98% of accuracy. So now I need to combine all the datasets for all the subjects at the same time and start to train the model at once
When I run the model at the beginning it takes 90 hours to train the model and I'm not sure about the accuracy at the end there might be overfitting or i need to increase the number of the epoch.What is the right way to increase the speed of the training and choose the right parameters for the CNN model?