ValueError: Missing data for input "reshape_6_input". You passed a data dictionary with keys [1]. Expected the following keys: ['reshape_6_input']

Viewed 27

The error seems the dataset is not balanced I'm not sure how to configure that ValueError: Missing data for input "reshape_6_input". You passed a data dictionary with keys [1]. Expected the following keys: ['reshape_6_input']

def main():
    
        #----Load Data----#
        # Read datafile into dataframe
        #USER NEEDS TO UPDATE THE FILENAME AND PATH/LOCATION IF DIFFERENT 
        f = 'compiled_data.csv' #compiled dataset filename
        path = '../learning/' #update with path for locating compiled datset
        data = pd.read_csv(str(path+f), header = 0)
        data.head(5)
    #----Data Preprocessing----#
    # Split into test and train datasets
    # Initialize dictionaries for X and Y for train and test
    # Key will be subject # 0-NUM_SUBJECTS, value will be the segments or labels
    X_train = dict()
    Y_train = dict()
    X_test = dict()
    Y_test = dict()
    
    #Preprocess data for each of 8 subjects within compiled dataset
    x_train, y_train, x_test, y_test = preprocess(data, PERCENT_TRAINING, WINDOW_SIZE, OVERLAP)
    X_train[i] = x_train
    Y_train[i] = y_train
    X_test[i] = x_test
    Y_test[i] = y_test
    
    # 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=(800,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=10,
                          epochs=50, 
                          callbacks=callbacks_list, 
                          validation_split=0.2,
                          verbose=0)
    
        #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 kept getting this error when i running the model even though it was working perfectly before i made some adjustment on the dataset can anyone tell me what could be the problem

0 Answers
Related