我的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如何过滤实际损失?我可以在源代码中找到这个吗?
谢谢!
答案 0 :(得分:0)
因此,在progbar中实际显示的是在打印时在给定时期内执行的所有批次的丢失的平均值。 (2个批次后的前2个,3个时期后的前3个等等)。所以 - 您可以通过对第一个n-th
损失值进行均值来获得n
时代之后打印的值。您可以在Progbar
定义中了解here。