简体   繁体   English

为什么我的 CNN 的准确率/损失在训练期间没有变化?

[英]Why doesn't my CNN's accuracy/loss change during training?

My goal is to train a convolutional neural network to recognise the images present in the mnist sign language dataset .我的目标是训练一个卷积神经网络来识别mnist 手语数据集中存在的图像。 Here is my attempt to process the data and train the model这是我处理数据和训练模型的尝试

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import os
import cv2
import random
from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D, Activation, Dropout, Flatten, Dense
import cv2
import keras
import sys
import tensorflow as tf
from keras import optimizers
import json

train_df = pd.read_csv("data/sign_mnist_train.csv")
test_df = pd.read_csv("data/sign_mnist_test.csv")
X = np.array(train_df.drop(["label"], axis=1))
y = np.array(train_df[["label"]])
X = X.reshape(-1, 28, 28, 1)
X = tf.cast(X, tf.float32)
model = Sequential()
model.add(Conv2D(28, (3,3), activation = 'relu'))
model.add(MaxPooling2D((2,2)))
model.add(Flatten())
model.add(Dense(24, activation = 'softmax'))
model.compile(optimizer='RMSprop',
              loss='binary_crossentropy',
              metrics=['accuracy'])
model.fit(X, y, epochs=10, validation_split=0.2)

and after running this I get this result运行这个之后我得到了这个结果

Epoch 1/10
687/687 [==============================] - 4s 6ms/step - loss: 174.9729 - accuracy: 0.0438 - val_loss: 174.6281 - val_accuracy: 0.0382
Epoch 2/10
687/687 [==============================] - 2s 3ms/step - loss: 174.9779 - accuracy: 0.0433 - val_loss: 174.6281 - val_accuracy: 0.0382
Epoch 3/10
687/687 [==============================] - 2s 3ms/step - loss: 174.9777 - accuracy: 0.0433 - val_loss: 174.6281 - val_accuracy: 0.0382

and this continues for the remaining 7 epochs.这在剩下的 7 个 epoch 中继续。 My model is slightly different from what I have provided (for brevity) but this sequential model has the same issue, which makes me suspect that the issue must come before the model = Sequential() line.我的模型与我提供的(为简洁起见)略有不同,但这个顺序模型有相同的问题,这让我怀疑问题必须出现在model = Sequential()行之前。 Furthermore, I have tried countless combinations of optimizers/loss and all those do is make the accuracy/loss converge to slightly different numbers, so I doubt that's the problem.此外,我尝试了无数优化器/损失的组合,所有这些都是使准确度/损失收敛到略有不同的数字,所以我怀疑这就是问题所在。

One of potential is that you use loss='binary_crossentropy' rather than loss='CategoricalCrossentropy' .潜力之一是您使用loss='binary_crossentropy'而不是loss='CategoricalCrossentropy'

Besides, you defined the split datasets for training and testing, but you again defined it as model.fit(X, y, epochs=10, validation_split=0.2) to split datasets with 20% for validation and 80% for training.此外,您定义了用于训练和测试的分割数据集,但您再次将其定义为model.fit(X, y, epochs=10, validation_split=0.2)以分割数据集,其中 20% 用于验证,80% 用于训练。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的 Tensorflow CNN 的准确度为零而损失不是? - why my Tensorflow CNN's accuracy is zero while loss is not? 在训练阶段我的 CNN 验证准确性和损失函数的奇怪行为 - Weird behaviour for my CNN validation accuracy and loss function during training phase 在keras训练中准确性不会改变,损失几乎不会减少 - Accuracy doesn't change over keras training, loss barely decreases 为什么 Keras 的 ModelCheckPoint 在训练期间没有保存我最好的 model 具有最高的验证准确率? - Why doesn't Keras' ModelCheckPoint save my best model with the highest validation accuracy during training? 为什么在 CNN 迁移学习期间,我的损失和准确率会随着每个 epoch 不断上升和下降? - Why does my loss and accuracy keep going up and down with each epoch during CNN transfer learning? 我的损失函数在训练期间没有得到更小的值 - My Loss Function doesn't get smaller values during training Tensorflow CNN模型不训练吗? 持续的损失和准确性 - Tensorflow CNN model not training? Constant loss and accuracy 验证损失和验证准确度在训练期间不会改变 - Validation Loss and Validation Accuracy do not change during training Keras自动编码器的精度/损耗不变 - Keras autoencoder accuracy/loss doesn't change 我的 CNN 网络验证准确性卡在 epoch 2 并且没有改变 - My CNN network validation accuracy get stuck at epoch 2 and doesn't change
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM