Exemple #1
0
    def __init__(self, n_layer, lstm_unit, input_shape, feature, data_type):
        DATA = load_var(data_type)
        self.EMOTIONS = DATA['EMOTIONS']

        self.model = Sequential()
        if n_layer > 1:
            self.model.add(
                LSTM(lstm_unit,
                     return_sequences=True,
                     input_shape=input_shape,
                     dropout=0.2))
            layer_count = 1
            while layer_count < n_layer:
                if layer_count == n_layer - 1:
                    self.model.add(
                        LSTM(lstm_unit, return_sequences=False, dropout=0.2))
                else:
                    self.model.add(
                        LSTM(lstm_unit, return_sequences=True, dropout=0.2))
                layer_count += 1
        else:
            self.model.add(
                LSTM(lstm_unit,
                     return_sequences=False,
                     input_shape=input_shape,
                     dropout=0.2))
        nb_class = len(self.EMOTIONS)
        self.model.add(Dense(nb_class, activation='softmax'))

        current_time = time.strftime("%Y%m%d-%H%M%S")
        self.base_dir = '../LSTM/' + data_type + '/' + feature + '/'
        self.model_dir = 'LSTM_' + str(n_layer) + '_' + str(
            lstm_unit) + '_' + current_time + '/'
        filename = 'LSTM.h5'
        self.model_file = self.base_dir + self.model_dir + filename
Exemple #2
0
 def __init__(self, model, base_dir, scores=[]):
     DATA = load_var(data_type)
     self.EMOTIONS = DATA['EMOTIONS']
     self.model = model
     self.scores = scores
     self.base_dir = '../SVM/' + data_type + '/' + feature + '/'
Exemple #3
0
    # plot normal confusion matrix
    fig2, ax2 = plt.subplots()
    plot_confusion_matrix(cm,
                          title='LSTM',
                          float_display='.0f',
                          class_names=EMOTIONS)
    plt.savefig(base_dir + 'cm_test.png')

    df = pd.DataFrame(cm_percent, index=EMOTIONS, columns=EMOTIONS)
    df.index.name = 'Actual'
    df.columns.name = 'Predicted'
    df.to_csv(base_dir + 'confusion_matrix_test.csv', float_format='%.4f')


if __name__ == '__main__':
    feature = 'VGG16'
    data_type = 'Basic'
    eval_mode = 'game'
    DATA = load_var(data_type)
    EMOTIONS = DATA['EMOTIONS']
    base_dir = '../best model/' + data_type + '/' + feature + '/'
    model_file = base_dir + 'LSTM.h5'

    # evaluate the model with test set
    X_val, y_val, X_test, y_test = load_test_data(data_type,
                                                  feature,
                                                  eval_mode=eval_mode)
    model = load_model(model_file)
    print(model.summary())
    display_scores(model, X_val, y_val, X_test, y_test)
    save_results(model, X_test, y_test, EMOTIONS, base_dir)