tf2crf
tf2crf copied to clipboard
How load CRF model in onnx?
Hi,
I am trying to accelerate a NLP pipeline using keras-onnx. The Keras model consisting a CRF layer (tf2crf) on top of the BiLSTM layer. I would appreciate it if you could direct me how to run the model via keras_onnx
def build_model():
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Bidirectional(tf.keras.layers.LSTM(internal_unit, return_sequences=True), input_shape=(seq_length, vector_dim)))
if drop_out_rate >0 and drop_out_rate <1:
model.add(tf.keras.layers.Dropout(drop_out_rate))
model.add(tf.keras.layers.TimeDistributed(tf.keras.layers.Dense(num_tags, activation=activation)))
crf = CRF(num_tags)
model.add(crf)
model.compile (loss=crf.loss, metrics=[crf.accuracy], optimizer=model_optimizer)
return model
model = build_model()
model.load_weights("model.h5")
onnx_model = keras2onnx.convert_keras(model, model.name)
The output is:
ValueError: Unable to find out a correct type for tensor type = <dtype: 'variant'> of sequential_1/crf_1/scan/while/exit/_103:0
Versions:
Python: 3.7.10 Tensorflow: 2.3.0 Keras: 2.2.4 tf2crf: 0.1.13
Thanks!