【问题标题】:Training checkpoints for deep learning with Keras使用 Keras 训练深度学习检查点
【发布时间】:2021-05-26 22:50:36
【问题描述】:

我正在使用 Google Colab,并节省了我的驱动器的重量。

培训:

def train(model, network_input, network_output):
""" train the neural network """
filepath = "/content/gdrive/MyDrive/weights-improvement-{epoch:02d}-{loss:.4f}-bigger.hdf5"
checkpoint = ModelCheckpoint(
    filepath,
    monitor='loss',
    verbose=0,
    save_best_only=True,
    mode='min'
)
callbacks_list = [checkpoint]

model.fit(network_input, network_output, epochs=200, batch_size=128, callbacks=callbacks_list)

经过一段时间的训练,我得到了重量: weights in my drive

然后我在不修改函数的情况下继续训练,输出单元格如下所示: output cell

我如何知道训练是从迄今为止的最佳权重(即“weights-improvement-06-4.1851-bigger.hdf5”)恢复,还是刚刚从头开始?如果它是通过保存的重量进行训练,它不应该以某种方式显示吗?也许向我展示了从 Epoch 4/200 而不是 1/200 开始,epochs 从它停止的地方继续。

【问题讨论】:

    标签: python keras deep-learning google-colaboratory checkpoint


    【解决方案1】:

    如果您仍在使用相同的实例化模型对象(即您尚未实例化新模型对象),它将从中断处继续训练 - 不会重新开始。

    但是,如果您想使用相同的配置实例化一个新模型并从之前保存的一组权重(检查点)开始,您可以使用 tensorflow 的 latest_checkpoint 在传递这些之前从您的目录中加载最新的检查点权重模型的权重。

    from tensorflow.train import latest_checkpoint
    
    last_ckpt = latest_checkpoint(os.path.join('my','checkpoint','directory'))
    # this is the newly instantiated model using the same config
    model.load_weights(last_ckpt)
    

    【讨论】:

      猜你喜欢
      • 2018-10-25
      • 2017-06-15
      • 2019-10-20
      • 2019-12-30
      • 2018-01-09
      • 1970-01-01
      • 1970-01-01
      • 2021-05-05
      • 2020-03-24
      相关资源
      最近更新 更多