简体   繁体   English

将 TFLite (TensorFlow) 转换为 MLModel (Apple)

[英]Convert TFLite (TensorFlow) to MLModel (Apple)

I'm trying to convert TFLite Face Mesh model to MLModel (Apple).我正在尝试将 TFLite Face Mesh 模型转换为 MLModel (Apple)。

TFLite model description: https://drive.google.com/file/d/1VFC_wIpw4O7xBOiTgUldl79d9LA-LsnA/view TFLite 模型说明: https ://drive.google.com/file/d/1VFC_wIpw4O7xBOiTgUldl79d9LA-LsnA/view

TFLite actual .tflite file: https://github.com/google/mediapipe/blob/master/mediapipe/models/face_landmark.tflite TFLite 实际 .tflite 文件: https : //github.com/google/mediapipe/blob/master/mediapipe/models/face_landmark.tflite

Looking at CoreMLTools provided by Apple ( https://coremltools.readme.io/docs/introductory-quickstart ) seems like it's possible, but all the samples codes demonstrate conversation from Keras and not from TFLite (although it's clearly supported):纵观苹果提供CoreMLTools( https://coremltools.readme.io/docs/introductory-quickstart )好像它是可能的,但所有的样本代码从演示谈话Keras而不是从TFLite (尽管它明确支持):

在此处输入图片说明

How does one convert TFLite model to MLModel model?如何将 TFLite 模型转换为 MLModel 模型?

As far as I know, there is no direct conversion from TFLite to Core ML.据我所知,没有从 TFLite 到 Core ML 的直接转换。 Someone could create such a converter but apparently no one has.有人可以创建这样的转换器,但显然没有人拥有。

Two options:两种选择:

  1. Do it yourself.自己做。 There is a Python API to read the TFLite file (flatbuffers) and an API to write Core ML files (NeuralNetworkBuilder in coremltools).有一个 Python API 来读取 TFLite 文件(flatbuffers)和一个 API 来编写 Core ML 文件(coremltools 中的 NeuralNetworkBuilder)。 Go through the layers of the TFLite model one-by-one, and add them to the NeuralNetworkBuilder, then save as a .mlmodel file.将 TFLite 模型的各个层一一遍历,将它们添加到 NeuralNetworkBuilder 中,然后另存为 .mlmodel 文件。

  2. Let TFLite do this for you.让 TFLite 为您做这件事。 When you use the CoreMLDelegate in TFLite, it actually performs the model conversion on-the-fly and saves a .mlmodel file (or the compiled version, .mlmodelc).当您在 TFLite 中使用 CoreMLDelegate 时,它​​实际上会即时执行模型转换并保存一个 .mlmodel 文件(或编译版本,.mlmodelc)。 Then it uses Core ML to run this model.然后它使用 Core ML 来运行这个模型。 You can write some code to load the model with TFLite using the CoreMLDelegate, then grab the .mlmodel file that this created from the app bundle and use that.您可以编写一些代码来使用 CoreMLDelegate 使用 TFLite 加载模型,然后从应用程序包中获取它创建的 .mlmodel 文件并使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM