无法在Google Colab中加载经过训练的模型

时间:2020-08-22 12:56:42

标签: python tensorflow keras google-colaboratory metrics

我训练了一个CNN并将其保存在Google云端硬盘中,现在我正尝试加载它并使用其他数据集对其进行测试,但是加载时遇到了问题。有人可以帮我吗?

from google.colab import drive
drive.mount('/content/drive')

import tensorflow as tf
import keras
newmodel =  tf.keras.models.load_model('/content/drive/My Drive/Programa2/New_UNet.h5')
newmodel.summary()

错误消息:

/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/utils/generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
    376       if obj is None:
    377         raise ValueError(
--> 378             'Unknown ' + printable_module_name + ': ' + object_name)
    379     # Classes passed by name are instantiated with no args, functions are
    380     # returned as-is.

ValueError: Unknown metric function: dice_coef

dice_coef是在称为Metrics的代码中创建的用于评估细分结果的函数。

model.compile(optimizer=opt, loss='binary_crossentropy', metrics=['accuracy',Metrics.dice_coef,Metrics.precision,Metrics.sensitivity,Metrics.specificity])

0 个答案:

没有答案