我有一个.tflite
模型,它使用名为MaxPoolingWithArgmax2D
、MaxUnpooling2D
和Convolution2DTransposeBias
的自定义操作。这些操作实际上不是自定义操作,因为它们已经存在于tensorflow中(MaxPoolWithArgmax、MaxUnpooling2D、conv2d_transpose)
在咨询了this guide之后,我发现我必须为这些操作编写一个内核和一个接口。
有没有一种方法可以构建tensorflow源代码,而无需为这些操作编写自定义实现,因为它们已经存在于库中?唯一的问题是,我使用的模型已经将它们重命名,因此它们被识别为自定义操作。我的目标是使用这个模型进行推理。
编辑:这些操作不是select操作。它们是存在于基础库中的内置操作。但是,编写此模型的人对它们进行了重命名,这使得它们成为自定义操作。
编辑2:供参考的照片:
发布于 2021-04-22 05:19:45
您可以通过TFLite中的选择TF选项启用现有TF操作。
例如,在转换阶段,您可以启用它们:
converter.target_spec.supported_ops = [
tf.lite.OpsSet.TFLITE_BUILTINS, # enable TensorFlow Lite ops.
tf.lite.OpsSet.SELECT_TF_OPS # enable TensorFlow ops.
]
对于推理阶段,请确保链接了select tf依赖项。使用TF Python API时,会自动开启。
请参考此link。
在自定义运算符中,其中一些的自定义运算符实现正在作为感知运算符包分发。
from tensorflow.lite.kernels.perception import pywrap_perception_ops as perception_ops_registerer
from tensorflow.lite.python import interpreter as interpreter_wrapper
interpreter = interpreter_wrapper.InterpreterWithCustomOps(
model_content=model,
custom_op_registerers=[
perception_ops_registerer.PerceptionOpsRegisterer
])
请看一下这个link。
https://stackoverflow.com/questions/67196996
复制相似问题