【问题标题】:Keras ModelCheckpoint monitor multiple valuesKeras ModelCheckpoint 监控多个值
【发布时间】:2018-02-25 07:23:00
【问题描述】:

我想使用 Keras ModelCheckpoint 回调来监控几个参数(我有一个多任务网络)。只有一个回调有可能吗?还是我需要在很多回调中这样做??

创建 ckechpoint :

checkpointer = ModelCheckpoint(filepath='checkpoints/weights-{epoch:02d}.hdf5', monitor='val_O1_categorical_accuracy' , verbose=1, save_best_only=True, mode='max')

我要监控的第二个参数:val_O2_categorical_accuracy

在列表中这样做是行不通的。即

checkpointer = ModelCheckpoint(filepath='checkpoints/weights-{epoch:02d}.hdf5', monitor=['val_O1_categorical_accuracy','val_O2_categorical_accuracy'] , verbose=1, save_best_only=True, mode='max')

TypeError: unhashable type: 'list'

【问题讨论】:

    标签: python tensorflow keras conv-neural-network keras-2


    【解决方案1】:

    恐怕您将不得不在不同的情况下执行此操作。想想这里发生了什么 -

    checkpointer = ModelCheckpoint(filepath='checkpoints/weights-{epoch:02d}.hdf5', monitor='val_O1_categorical_accuracy' , verbose=1, save_best_only=True, mode='max')
    

    当您通过监视val_O1_categorical_accuracy 保存模型时,它会在伪代码中执行以下操作 -

    for each epoch:
        check the val_O1_categorical_accuracy after updating weights
        if this metric is better in this epoch than the previous ones:
            save the model
        else
            pass
    

    所以真正指定多个monitor 超出了范围。在这种情况下,它必须是一个非此即彼的选择,因为基于 monitor 指标,在其他相互冲突的模型中,只有一个模型可能是最好的。

    【讨论】:

    • 好的,谢谢,我想我会添加第二个指标来计算两次损失的平均值,
    • 是的,这是一个很好的选择。我从来没有玩过monitor 参数。可能它确实支持callable。无论如何,如果您的查询已解决,请标记为答案,以便其他搜索类似内容的人能够找到帮助。否则,请自行发布答案,以防万一你想通了并标记它
    猜你喜欢
    • 1970-01-01
    • 2016-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多