将自定义 BERT 问答模型转换为 Tflite 模型

时间:2021-05-01 14:30:07

标签: python tensorflow tensorflow-lite bert-language-model

我有这个 BERT 模型,我对它进行了微调以回答问题,使用 SQuAD 数据集进行训练。但是,当我尝试按照指示 here 将其转换为 tflite 模型时,出现以下错误:

 'tf.Reshape' op requires 'shape' to have at most one dynamic dimension, but got multiple dynamic dimensions at indices 0 and 1
<unknown>:0: note: loc("StatefulPartitionedCall"): 

以下是转换代码

import tensorflow as tf

saved_model_dir = '/home/vineetkalghatgi/Downloads/mymodel-20210413T165017Z-001/mymodel'

# Convert the model
converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir) # path to the SavedModel directory
tflite_model = None
try:
  tflite_model = converter.convert()
except Exception as e:
  print(e)
  exit()

# Save the model.
with open('model.tflite', 'wb') as f:
  f.write(tflite_model)

0 个答案:

没有答案