white346
2022-04-17 15:51
采纳率: 0%
浏览 32

在使用循环神经网络处理序列问题时,训练二分类模型acc最高只能到0.6 loss一直是0.69附近怎么办?

问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
from keras.layers.core import Dense, Dropout, Activation
from keras.layers.embeddings import Embedding
import keras
import numpy as np

x_train = np.load(args["train_data"] + "/train/seq/" + "RNN_data_train_" + args["len_seq"] + "_" + str(j) + ".npy")
    y_train = np.load(args["train_data"] + "/train/label/" + "RNN_label_train_" + args["len_seq"] + "_" + str(j) + ".npy")
    # 将整型的类别标签转为onehot编码
    y_in = keras.utils.to_categorical(y_train, 2)
    # len_s = int(args["len_seq"])
    print("train_data:", x_train)
    print("train_data_shape:", x_train.shape)
    print("train_label:", y_in)
    print("train_label_shape:", y_in.shape)

    model = Sequential()
    model.add(Embedding(22, 16, input_length=11))
    model.add(Dropout(0.2))
    model.add(LSTM(16, return_sequences=True, activation='relu'))
    model.add(LSTM(16, return_sequences=False))
    model.add(Dropout(0.2))
    model.add(Dense(10, activation='relu'))
    model.add(Dropout(0.2))
    model.add(Dense(2, activation='softmax'))
    model.summary()

    callback = keras.callbacks.EarlyStopping(monitor='val_loss', patience=30)
    model.compile(loss=keras.losses.categorical_crossentropy,
                  optimizer=keras.optimizers.RMSprop(lr=0.001),
                  metrics=['accuracy'])
    train_history = model.fit(x_train, y_in, batch_size=8000, epochs=400,
                       verbose=2, validation_split=0.2, shuffle=True,callbacks=[callback])

    model.save(modelfile/rnn_mode_new_dropout.h5)
我想要达到的结果

1条回答 默认 最新

相关推荐 更多相似问题