用TensorFlow Lite转换模型时,报如下错误:
Some of the operators in the model are not supported by the standard TensorFlow Lite
runtime. If those are native TensorFlow operators, you might be able to use the extended
runtime by passing --enable_select_tf_ops, or by setting
target_ops=TFLITE_BUILTINS,SELECT_TF_OPS when calling tf.lite.TFLiteConverter().
Otherwise, if you have a custom implementation for them you can disable this error with --
allow_custom_ops, or by setting allow_custom_ops=True when calling
tf.lite.TFLiteConverter(). Here is a list of builtin operators you are using: ADD,
AVERAGE_POOL_2D, CAST, CONCATENATION, CONV_2D, DEPTHWISE_CONV_2D,
FULLY_CONNECTED, GREATER_EQUAL, LESS, MUL, RESHAPE, SELECT,
TRANSPOSE. Here is a list of operators for which you will need custom implementations:
RandomUniform.
解决方法:
import tensorflow as tf
converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir)
# 在convert()前加上这句
converter.allow_custom_ops=True
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)
参考:Some of the operators in the model are not supported by the standard TensorFlow Lite runtime. If th