gpt4 book ai didi

python - Keras 训练循环如何过滤损失值?

转载 作者:行者123 更新时间:2023-11-30 09:19:31 24 4
gpt4 key购买 nike

我的 keras 模型设置如下(TF 1.2.1):

import tensorflow.contrib.keras as keras

model = keras.models.Sequential()

...

model.compile(loss=keras.losses.mean_squared_error,
optimizer=keras.optimizers.Adam(lr=1e-4))

model.summary()


Layer (type) Output Shape Param #
=================================================================
conv2d_1 (Conv2D) (None, 29, 29, 64) 6336
_________________________________________________________________
conv2d_2 (Conv2D) (None, 13, 13, 128) 204928
_________________________________________________________________
conv2d_3 (Conv2D) (None, 11, 11, 256) 295168
_________________________________________________________________
conv2d_4 (Conv2D) (None, 5, 5, 256) 590080
_________________________________________________________________
flatten_1 (Flatten) (None, 6400) 0
_________________________________________________________________
dense_1 (Dense) (None, 2) 12802
=================================================================
Total params: 1,109,314
Trainable params: 1,109,314
Non-trainable params: 0

输出是一个简单的浮点向量,它会根据需要收敛。损失是均方误差。示例输出:

 18/100 [====>.........................] - ETA: 30s - loss: 31.5118
19/100 [====>.........................] - ETA: 29s - loss: 30.7577
20/100 [=====>........................] - ETA: 29s - loss: 29.7815
21/100 [=====>........................] - ETA: 28s - loss: 29.0535
22/100 [=====>........................] - ETA: 28s - loss: 28.1963
23/100 [=====>........................] - ETA: 28s - loss: 27.3314
24/100 [======>.......................] - ETA: 28s - loss: 26.7219
25/100 [======>.......................] - ETA: 28s - loss: 25.9702
26/100 [======>.......................] - ETA: 27s - loss: 25.4181
27/100 [=======>......................] - ETA: 27s - loss: 25.0638
28/100 [=======>......................] - ETA: 27s - loss: 24.6081
29/100 [=======>......................] - ETA: 26s - loss: 24.0928

损失似乎在稳步减少。但是,当我查看实际损失 (keras.callbacks.LambdaCallback@on_batch_end) 时,情况并不那么顺利:

25.473383
28.051779
20.519075
13.204493
20.74946
21.246254
25.611149
13.194682
13.268744
15.408422
17.183851
11.232637
14.493115
10.196851

我试图深入研究 Keras 源代码,但无法理解幕后发生的事情。 Keras 如何过滤实际损失?在源代码中哪里可以找到这个?

谢谢!

最佳答案

因此,progbar 中实际显示的是打印时给定时期内执行的所有批处理的损失平均值。 (2 个批处理后前 2 个的平均值,3 个时期后前 3 个的平均值,依此类推)。因此,您可以通过对第一个 n 损失值取平均值来获得第 n 个 epoch 之后打印的值。您可以阅读hereProgbar 定义中。

关于python - Keras 训练循环如何过滤损失值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45138064/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com