加载建筑提取模型遇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
相关产品推荐
相关产品推荐

