netrack / keras-metrics

Metrics for Keras. DEPRECATED since Keras 2.3.0
MIT License
165 stars 23 forks source link

load_model problem #13

Closed Bjoux2 closed 5 years ago

Bjoux2 commented 5 years ago

keras-metrics is useful in the process of training

model.compile(loss=keras.losses.categorical_crossentropy, optimizer=keras.optimizers.Adadelta(), metrics=['accuracy', keras_metrics.precision(), keras_metrics.recall()])

during the training, it reported this:

1766016/1839646 [=====>..] - ETA: 2s - loss: 0.3919 - acc: 0.8308 - precision: 0.6595 - recall: 0.3231 1767424/1839646 [=====>..] - ETA: 2s - loss: 0.3919 - acc: 0.8308 - precision: 0.6595 - recall: 0.3231 1768832/1839646 [=====>..] - ETA: 2s - loss: 0.3920 - acc: 0.8307 - precision: 0.6594 - recall: 0.3231 1770368/1839646 [=====>..] - ETA: 2s - loss: 0.3920 - acc: 0.8307 - precision: 0.6594 - recall: 0.3232 1771776/1839646 [=====>..] - ETA: 2s - loss: 0.3919 - acc: 0.8308 - precision: 0.6595 - recall: 0.3232

and I save the model with the code: model.save(model_save_path + '/mlp_pssm_%s.h5' % short_mid_long)

things going well, so far.

however, when I was trying to load the model with the code: clf = load_model(models_path + '/%s_%s.h5' % (model_type,contact_type))

I got this error: ValueError: Unknown metric function: {'class_name': 'precision', 'config': {'name': 'precision', 'trainable': True}}

How to fix this error? Thanks!

Bjoux2 commented 5 years ago

besides, I tried to add keras_metrics.precision() and keras_metrics.recall() in the custom_objects: clf = load_model(models_path + '/%s_%s.h5' % (model_type, contact_type), custom_objects={"precision": keras_metrics.precision(), "recall": keras_metrics.recall()})

error: ValueError: Unknown metric function: {'class_name': <keras_metrics.metrics.precision object at 0x000001BB9FD2B4E0>, 'config': {'name': <keras_metrics.metrics.precision object at 0x000001BB9FD2B4E0>, 'trainable': True}}

ybubnov commented 5 years ago

@Bjoux2, thank you for posting the issue! This looks like the metrics classes are missing support of loading, I'll try to see how can it can be fixed.

kccheung commented 5 years ago

I got the same problem. Looking forward on the updates which fixes this.

chenjian591 commented 5 years ago

I got the same problem, Even if I added the custom-defined metric function in the keras.metrics.py

ybubnov commented 5 years ago

Sorry guys for a late response, it looks like the keras package is completely broken due to implementation of this function: https://github.com/keras-team/keras/blob/2.2.1/keras/engine/saving.py#L222.

It seems there is a workaround with load_weigths method, but the complete solution requires a fix to keras itself.

ybubnov commented 5 years ago

Should be resolved in #25, version 0.0.7.