我正在培训多种型号(在Google Colab上),并使用Joblib保存它们。然后,我正在下载这些文件并使用Joblib加载它们,但是我会遇到以下错误;
无法还原类型_tf_keras_metric的自定义对象,
我正在使用量表= ['fecuctiacy',特异性,tf.keras.metrics.precision()]编译模型,其中特定性是从 https://www.sabinasz.net/unbalanced-classes-classes-classes-machine-machine-learning/ 。
mobilenet_model = MobileNetV3Small(include_top=True, weights=None, classes=2, input_shape=(100, 100, 3))
mobilenet_model.compile(loss='binary_crossentropy', metrics=['accuracy', specificity, tf.keras.metrics.Precision()])
trained_model = mobilenet_model.fit(X_train, y_train)
joblib.dump(trained_model, 'mobilenet_model.joblib')
我尝试使用keras.models.load_model加载它们,但是我得到了一个错误打开文件(未找到文件签名),该文件根据表示文件已损坏(我想Joblib保存模型与Keras的Save_model函数不兼容) 。
我尝试使用keras.models.save_model保存文件并传递custic_objects = {'特殊性':特殊性,'precision':tf.keras.metrics.precision()},但该模型似乎没有预期的权重,因为当我评估它时,它的精度仅为0.5,当我训练时获得0.9时。
那我该怎么办?
I am training multiple models (on Google Colab) and saving them using joblib. I am then downloading these files and loading them using joblib, but I am getting the following error;
Unable to restore custom object of type _tf_keras_metric
I am compiling the models using metrics=['accuracy', specificity, tf.keras.metrics.Precision()], where specificity is a custom metric function from https://www.sabinasz.net/unbalanced-classes-machine-learning/.
mobilenet_model = MobileNetV3Small(include_top=True, weights=None, classes=2, input_shape=(100, 100, 3))
mobilenet_model.compile(loss='binary_crossentropy', metrics=['accuracy', specificity, tf.keras.metrics.Precision()])
trained_model = mobilenet_model.fit(X_train, y_train)
joblib.dump(trained_model, 'mobilenet_model.joblib')
I tried to load them using keras.models.load_model but I get a Error opening file (File signature not found) which according to Error opening file in H5PY (File signature not found) means the file is corrupt (I imagine that the way joblib saves models is not compatible with keras's save_model function).
I tried using keras.models.save_model to save a file and passing in custom_objects={'specificity': specificity, 'precision': tf.keras.metrics.Precision()}, but the model seems to be saved without the pretrained weights because when I evaluate it, it only has 0.5 accuracy, when it was getting 0.9 when I trained it.
So what can I do?
发布评论