You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

加载建筑提取模型遇ValueError:未知metric函数dice_coef求助

问题解决方法

你的问题出在加载模型时,只在custom_objects里指定了自定义损失函数bce_dice_loss,但没有添加自定义评估指标dice_coef。因为你的模型在保存时是用dice_coef作为评估指标的,所以加载时必须把它也传入custom_objects中,Keras才能识别这个指标。

修改后的代码如下:

from tensorflow.keras.models import load_model
from loss import bce_dice_loss, dice_coef


model = load_model(
    'D:\\RESEARCH\\IITR\\BUILDING_EXTRACTION_PhD_Final_WORK\\DATASET\\ISPRS_DATASET\\Toronto\\Toronto\\ImagesDolon\\output\\weights\\my_model.h5',
    custom_objects={'bce_dice_loss': bce_dice_loss, 'dice_coef': dice_coef}
)

这样就能正确加载包含自定义损失和指标的模型了。

内容的提问来源于stack exchange,提问作者DolonPrabhakar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 04:05:26