首页 > 解决方案 > 如何使用使用自定义操作的模型从源代码构建张量流,这些操作是现有操作的重命名版本?

问题描述

我有一个.tflite使用自定义操作的模型,称为MaxPoolingWithArgmax2DMaxUnpooling2DConvolution2DTransposeBias。这些操作实际上不是自定义操作,因为它们已经存在于 tensorflow 中(MaxPoolWithArgmaxMaxUnpooling2Dconv2d_transpose

查阅本指南后,我发现我必须为这些操作编写内核和接口。

有没有办法在不为这些操作编写自定义实现的情况下构建 tensorflow 源代码,因为它们已经存在于库中?唯一的问题是我使用的模型已将它们重命名,因此它们被识别为自定义操作。我的目标是用这个模型进行推理。

编辑:这些操作不是选择操作。它们是基本库中的内置操作。但是,编写此模型的人将它们重命名,这使它们成为自定义操作。

编辑2:供参考的照片:在此处输入图像描述

标签: tensorflowdeep-learningtensorflow-lite

解决方案


您可以通过 TFLite 中的 Select 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 时,会自动启用。

请参考此链接


在自定义操作中,其中一些操作的自定义操作实现作为感知操作包分发。

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
          ])

请看一下这个链接


推荐阅读