【发布时间】:2021-05-22 09:00:07
【问题描述】:
我想针对不同的批量大小训练我的模型,即:[64, 128] 我正在用下面的 for 循环来做这件事
epoch=2
batch_sizes = [128,256]
for i in range(len(batch_sizes)):
history = model.fit(x_train, y_train, batch_sizes[i], epochs=epochs,
callbacks=[early_stopping, chk], validation_data=(x_test, y_test))
对于上述代码,我的模型产生以下结果:
Epoch 1/2
311/311 [==============================] - 157s 494ms/step - loss: 0.2318 -
f1: 0.0723
Epoch 2/2
311/311 [==============================] - 152s 488ms/step - loss: 0.1402 -
f1: 0.4360
Epoch 1/2
156/156 [==============================] - 137s 877ms/step - loss: 0.1197 -
f1: **0.5450**
Epoch 2/2
156/156 [==============================] - 136s 871ms/step - loss: 0.1132 -
f1: 0.5756
看起来模型在完成批量大小 64 的训练后继续训练,即我想让我的模型从头开始训练下一批,我该怎么做,请指导我。 ps:我尝试过的:
epoch=2
batch_sizes = [128,256]
for i in range(len(batch_sizes)):
history = model.fit(x_train, y_train, batch_sizes[i], epochs=epochs,
callbacks=[early_stopping, chk], validation_data=(x_test, y_test))
keras.backend.clear_session()
它也没有工作
【问题讨论】:
标签: python loops keras model-fitting