tensorflow - 如何使用使用自定义操作的模型从源代码构建张量流,这些操作是现有操作的重命名版本?
问题描述
我有一个.tflite
使用自定义操作的模型,称为MaxPoolingWithArgmax2D
、MaxUnpooling2D
和Convolution2DTransposeBias
。这些操作实际上不是自定义操作,因为它们已经存在于 tensorflow 中(MaxPoolWithArgmax,MaxUnpooling2D,conv2d_transpose)
查阅本指南后,我发现我必须为这些操作编写内核和接口。
有没有办法在不为这些操作编写自定义实现的情况下构建 tensorflow 源代码,因为它们已经存在于库中?唯一的问题是我使用的模型已将它们重命名,因此它们被识别为自定义操作。我的目标是用这个模型进行推理。
编辑:这些操作不是选择操作。它们是基本库中的内置操作。但是,编写此模型的人将它们重命名,这使它们成为自定义操作。
解决方案
您可以通过 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
])
请看一下这个链接。
推荐阅读
- excel - 运行时错误 1004 方法添加对象表失败
- python - 编程绝对编码器
- logging - log4j 用参数指定日志文件
- reactjs - 拖放在 React App 上不起作用。如何在我的代码中实现 DndContext
- javascript - 如何将第三方插件与 AMP 集成
- spring - 自定义 spring 验证结果
- javascript - 如何使用 javascript 截断查询结果?
- angular - 以角度运行测试时出错:找不到管道“分页”(“
- javascript - 我需要计算文本区域中的孟加拉语和英文字母
- javascript - 在 FluentUI 的 DetailsList 中的一组标题上添加嵌套标题