为什么Keras的train_on_batch在第二个时间段产生零损失和准确性? [英] Why does Keras' train_on_batch produce zero loss and accuracy at the second epoch?

查看:356
本文介绍了为什么Keras的train_on_batch在第二个时间段产生零损失和准确性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个大数据集,因此我尝试使用train_on_batch(或适合epoch = 1)

I am using a big dataset, and so I'm trying to use train_on_batch(or fit with epoch = 1)

model = Sequential()
model.add(LSTM(size,input_shape=input_shape,return_sequences=False))
model.add(Dense(output_dim))
model.add(Activation('softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=["accuracy"])

for e in range(nb_epoch):
    for batch_X, batch_y in batches:
        model.train_on_batch(batch_X,batch_y)
        # or
        # model.fit(batch_X,batch_y,batch_size=batch_size,nb_epoch=1,verbose=1,shuffle=True,)

但是,当训练开始时,会发生这种情况:

But when training starts, this happens:

(0, 128)
Epoch 1/1
128/128 [==============================] - 2s - loss: 0.3262 - acc: 0.1130

(129, 257)
Epoch 1/1
128/128 [==============================] - 2s - loss: -0.0000e+00 - acc: 0.0000e+00

我等待多少个时间都没关系,它不会改变.即使更改批次大小,也会发生相同的事情:第一个批次具有良好的值,然后再次变为损失:-0.0000e + 00-acc:0.0000e + 00".

It doesn't matter how many epochs I wait, it doesn't change. Even If I change the batch size, the same thing happens: The first batch has good values and then it just goes to "loss: -0.0000e+00 - acc: 0.0000e+00" again.

有人可以帮助您了解这里发生的事情吗?

Can someone maybe help in understanding what's happening here?

推荐答案

这似乎是爆炸/消失梯度问题.就像有人说的那样,尝试调整您的学习率和/或NN层的深度/宽度

This seems like the exploding/vanishing gradient problem. Like someone said try tuning your learning rate and/or the depth/width of your NN layers

这篇关于为什么Keras的train_on_batch在第二个时间段产生零损失和准确性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆