BTHOG。
我定义并精调移动多语言bert模型,该模型使用以下keras代码构建:
bert_preprocess = hub.KerasLayer("https://tfhub.dev/tensorflow/bert_multi_cased_preprocess/3")
bert_encoder = hub.KerasLayer("https://tfhub.dev/tensorflow/mobilebert_multi_cased_L-24_H-128_B-512_A-4_F-4_OPT/1", trainable=True)
i = tf.keras.layers.Input(shape=(), dtype=tf.string, name='text')
x = bert_preprocess(i)
x = bert_encoder(x)
x = tf.keras.layers.Dropout(0.2, name="dropout")(x['pooled_output'])
x = tf.keras.layers.Dense(num_classes, activation='softmax', name="output")(x)
model = tf.keras.Model(i, x)最后,我将模型保存为tf保存模型,然后使用以下支持的操作系统将其转换为tflite版本:
tf.lite.OpsSet.TFLITE_BUILTINS, # enable TensorFlow Lite ops.
tf.lite.OpsSet.SELECT_TF_OPS # enable TensorFlow ops.当我试图使用tensorflow github:https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/examples/minimal的代码加载tflite转换模型时,问题就开始了。
我得到以下错误:
ERROR: Select TensorFlow op(s), included in the given model, is(are) not supported by this interpreter. Make sure you apply/link the Flex delegate before inference. For the Android, it can be resolved by adding "org.tensorflow:tensorflow-lite-select-tf-ops" dependency. See instructions: https://www.tensorflow.org/lite/guide/ops_select
ERROR: Node number 0 (FlexHashTableV2) failed to prepare.
Error at /home/nativ/dev/tflite_inference/minimal.cc:60我能做些什么来纠正这些错误呢?
发布于 2022-05-09 23:07:46
您的模型有一些to,您需要链接Select (也称为flex委托),它允许您为TFLite中作为本机操作不可用的操作运行TF内核。主要是您需要构建委托并将其链接到二进制文件。
bazel build -c opt --config=monolithic tensorflow/lite/delegates/flex:tensorflowlite_flex请参阅更多详细信息这里
https://stackoverflow.com/questions/72173423
复制相似问题