from keras.models import load_model
model = load_model(model_path)
会报错,需要在load_model函数中添加custom_objects参数,来声明自定义的层
(用keras搭建bilstm-crf,在训练模型时,使用的是:from keras_contrib.layers.crf import CRF)
from keras_contrib.layers.crf import CRF, crf_loss, crf_viterbi_accuracy
model = load_model(model_path, custom_objects={"CRF": CRF, 'crf_loss': crf_loss,
'crf_viterbi_accuracy': crf_viterbi_accuracy})