python-3.x - 训练损失和准确性以及验证准确性保持不变
问题描述
我正在尝试使用两个输入来训练 CNN 模型,但我注意到训练和验证的准确性仍然很高且保持不变。我的代码可能有问题。欢迎任何帮助解决这个问题。
from tensorflow.keras.models import Model
from tensorflow.keras.layers import Dense, Input, Dropout, concatenate
from tensorflow.keras.layers import Embedding, LSTM, GlobalMaxPooling1D
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.layers import Bidirectional
input_text = Input(shape=(100,), dtype='int32', name='input_text')
meta_input = Input(shape=(2,), name='meta_input')
embedding = Embedding(input_dim=len(tokenizer.word_index) + 1,
output_dim=300,
input_length=100)(input_text)
lstm = Bidirectional(LSTM(units=128,
dropout=0.9,
recurrent_dropout=0.9,
return_sequences=True),
merge_mode='concat')(embedding)
pool = GlobalMaxPooling1D()(lstm)
dropout = Dropout(0.5)(pool)
text_output = Dense(1, activation='sigmoid', name='aux_output')(dropout)
output = concatenate([text_output, meta_input])
output = Dense(n_codes, activation='relu')(output)
main_output = Dense(1, activation='softmax', name='main_output')(output)
model = Model(inputs=[input_text,meta_input], outputs=[output])
optimer = Adam(lr=.001)
model.compile(optimizer='adam',
loss='binary_crossentropy',
metrics=['accuracy'])
model.summary()
model.fit([X1, X2], [y],
validation_data=([X_valid1,X_valid2], [y_valid]),
batch_size=64, epochs=20, verbose=1)
结果:训练行:11416 验证行:2035 [ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 158] 型号:“model_6”
层(类型)输出形状参数#连接到
input_text (InputLayer) [(无, 100)] 0
embedding_7 (嵌入) (None, 100, 300) 889500 input_text[0][0]
bidirectional_7 (双向) (None, 100, 256) 439296 embedding_7[0][0]
global_max_pooling1d_7 (GlobalM (None, 256) 0 bidirectional_7[0][0]
dropout_7(丢弃)(无,256)0 global_max_pooling1d_7[0][0]
aux_output(密集)(无,1)257 dropout_7[0][0]
元输入(输入层)[(无,2)] 0
concatenate_7(连接)(无,3)0 aux_output[0][0]
meta_input[0][0]
密集_5(密集)(无,545)2180 concatenate_7[0][0]
总参数:1,331,233 可训练参数:1,331,233 不可训练参数:0
训练 11416 个样本,验证 2035 个样本 Epoch 1/20 11416/11416 [==============================] - 143s 13 毫秒/样本 - 损失:0.0254 - 准确度:0.9982 - val_loss:0.0236 - val_accuracy:0.9982 纪元 2/20 11416/11416 [======================= =======] - 143s 13ms/样本 - 损失:0.0233 - 准确度:0.9982 - val_loss:0.0235 - val_accuracy:0.9982 Epoch 3/20 11416/11416 [============= =================] - 150s 13ms/样本 - 损失:0.0233 - 准确度:0.9982 - val_loss:0.0233 - val_accuracy:0.9982 Epoch 4/20 11416/11416 [=== ===========================] - 166s 15ms/样本 - 损失:0.0232 - 准确度:0.9982 - val_loss:0.0234 - val_accuracy:0.9982 Epoch 5/20 11416/11416 [===============================] - 198s 17ms/样本 - 损失:0.0232 - 准确度: 0.9982 - val_loss:0.0234 - val_accuracy:0。9982 纪元 6/20 11416/11416 [==============================] - 236s 21ms/样本 - 损失:0.0232 -准确度:0.9982 - val_loss:0.0232 - val_accuracy:0.9982 纪元 7/20
解决方案
推荐阅读
- python - 如何在没有错误的情况下导出和导入 conda 环境
- python - 从 UNC 路径运行子进程
- c# - 你能帮我解决 Unity3d 项目中数组或枚举中的错误吗?
- python - 向所有客户端发送数据包 - Python UDP 服务器
- laravel - 如何将数据库连接和范围会话持久化到租户,以及如何在 laravel 多租户中为租户的用户配置 Laravel Fortify?
- sql - 按年和月提取布尔计数
- json - 如何用 Flutter 解析动态 JSON?
- sharepoint - 如何基于单个架构更新两个 SharePoint 列表?(电源应用程序)
- php - 带有 Larvalel api Nginx 配置的 Nuxt 前端
- python - 插入ascii转义字符时删除python中的双空格