我培训了keras CNN,监控以下指标:
METRICS = [
TruePositives(name='tp'),
FalsePositives(name='fp'),
TrueNegatives(name='tn'),
FalseNegatives(name='fn'),
BinaryAccuracy(name='accuracy'),
Precision(name='precision'),
Recall(name='recall'),
AUC(name='auc'),
]
然后是model.compile:
model.compile(optimizer='nadam', loss='binary_crossentropy',
metrics=METRICS)
它工作得很好,我保存了我的h5型号(model.h5)
现在我已经下载了该模型,我想在其他脚本中使用它导入模型,包括:
from keras.models import load_model
model = load_model('model.h5')
model.predict(....)
但在运行过程中,编译器返回:
ValueError: Unknown metric function: {'class_name': 'TruePositives', 'config': {'name': 'tp', 'dtype': 'float32', 'thresholds': None}}
我应该如何处理这个问题
先谢谢你
当您有自定义指标时,您需要遵循稍微不同的方法
custom_objects
和compile = False
加载模型我在这里展示方法
看起来您正在使用tensorflow教程。我也使用了这些精确的指标,也遇到了同样的问题。对我来说,有效的方法是用
compile = False
加载模型,然后用自定义度量编译它。然后您应该能够按预期使用model.predict(....)
相关问题 更多 >
编程相关推荐