keras-contrib
keras-contrib copied to clipboard
How to load the customized layer and loss function.
Hi,
I'm training the LSTM-CRF model for NER.
I used the keras_contrib.layers import CRF
as the CRF layer. Once I finished the training, I saved the model by model.save('testing_new_all_trainning_words.h5')
. But when I tried to load the model by
from keras.models import load_model
model = load_model('testing_new_all_trainning_words.h5')
I got exception: "ValueError: Unknown layer: CRF"
Required, as usual
from keras.models import load_model
Recommended method; requires knowledge of the underlying architecture of the model
from keras_contrib.layers.advanced_activations import PELU
Not recommended; however this will correctly find the necessary contrib modules
from keras_contrib import *
Load our model
model = load_model('example.h5')
Do try something like above , please refer to the readme file (Front page - last part)
@anand-sonawane It didn't work. I still get the same error. My keras version is 2.1.6
@doggeral Have you solved this issue? I have the same problem now.
from keras_contrib.layers import CRF
from keras_contrib.losses import crf_loss
from keras_contrib.metrics import crf_viterbi_accuracy
model= load_model('your_model.h5',custom_objects={'CRF':CRF,
'crf_loss':crf_loss,
'crf_viterbi_accuracy':crf_viterbi_accuracy})