简体   繁体   English

Keras 损失:0.0000e+00 且精度保持不变

[英]Keras loss: 0.0000e+00 and accuracy stays constant

I have 101 folders from 0-100 containing synthetic training images.我有 0-100 个包含合成训练图像的 101 个文件夹。 This is my code:这是我的代码:

dataset = tf.keras.utils.image_dataset_from_directory(
'Pictures/synthdataset5', labels='inferred', label_mode='int', class_names=None, color_mode='rgb', batch_size=32, image_size=(128,128), shuffle=True, seed=None, validation_split=None, subset=None,interpolation='bilinear', follow_links=False,crop_to_aspect_ratio=False
)

from keras.models import Sequential
from keras.layers import Dense, Conv2D, Flatten

model = Sequential()

model.add(Conv2D(32, kernel_size=5, activation='relu', input_shape=(128,128,3)))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(64, kernel_size=5, activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(128, kernel_size=3, activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(256, kernel_size=3, activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten())
model.add(Dense(1, activation='sigmoid'))

model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])

model.fit(dataset,epochs=75)

And I always get the same result for every epoch:而且我总是在每个时代得到相同的结果:

Epoch 1/75
469/469 [==============================] - 632s 1s/step - loss: 0.0000e+00 - accuracy: 0.0098

What's wrong???怎么了???

So turns out your loss might be the problem after all.事实证明,你的损失毕竟可能是问题所在。 If you use SparseCategoricalCrossentropy instead as loss it should work.如果您使用 SparseCategoricalCrossentropy 作为损失,它应该可以工作。

model.compile(optimizer='adam',
              loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
              metrics=['accuracy'])

After this you should adjust the last layer to:在此之后,您应该将最后一层调整为:

model.add(Dense(101, activation='softmax'))

Also don't forget to import import tensorflow as tf Let me know if this solves the issue.也不要忘记import tensorflow as tf让我知道这是否解决了问题。

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

相关问题 keras val_loss:0.0000e+00 - val_accuracy:0.0000e+00 - keras val_loss: 0.0000e+00 - val_accuracy: 0.0000e+00 为什么我的准确率总是0.0000e+00,而且损失巨大? - Why is my accuracy always 0.0000e+00, and loss and huge? 如何解决 LSTM 问题中的 loss: nan &accuracy: 0.0000e+00? 张量流 2.x - How to solve loss: nan & accuracy: 0.0000e+00 in a LSTM problem? Tensorflow 2.x 我使用 fit_generator 的损失是 0.0000e+00(使用 Keras) - My loss with fit_generator is 0.0000e+00 (using Keras) Twitter 情绪分析常数零(0.0000e+00)损失值 - Twitter Sentiment Analysis Constant Zero (0.0000e+00) Loss value CNN 精度:0.0000e+00 用于图像的多分类 - CNN accuracy: 0.0000e+00 for multi-classification on images 获得精度:0.0000e+00 在我的张量流 model - Getting accuracy: 0.0000e+00 in my Tensor flow model “损失:0.0000e+00 - acc: 1.0000 - val_loss: 0.0000e+00 - val_acc: 1.0000”是什么意思? - what does "loss: 0.0000e+00 - acc: 1.0000 - val_loss: 0.0000e+00 - val_acc: 1.0000" mean? Conv2d Tensorflow 结果错误 - 准确度 = 0.0000e+00 - Conv2d Tensorflow results wrong - accuracy = 0.0000e+00 如何修复分类分类中的“val_accuracy: 0.0000e+00”? - How to fix “val_accuracy: 0.0000e+00” in categorical classification?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM