将预训练的张量流模型转换为张量流服务

converting pretrained tensorflow models for tensorflow serving

我正在尝试使用 tensorflow 服务。但是,任何可供下载的预训练模型(如来自此处:the TF detection zoo)在服务模型所需的 saved_models/variables 目录中没有任何文件。

如何使用检测模型动物园提供的预训练模型在 saved_models/variables 目录中创建所需的文件?

有一些信息 from the official documentation,但它没有涵盖我将预训练模型转换为服务的用例。

我尝试过的其他事情是使用 tensorflow 服务示例。然而,现有的文档大多以 Resent 实现为例,resnet 的预训练模型已被 Tensorflow 移除。 This is the linked that tutorials use,请注意,没有直接 link 下载模型。顺便说一句,但更有趣的是,Tensorflow Serving 存储库中的 python 示例不适用于 Tensorflow 2.0。

看来这个 link 可能对转换有用:https://github.com/tensorflow/models/issues/1988

好的,截至编写对象检测教程时仅支持 tensorflow 1.12.0。

这样做有点困难,因为它是如此多层次,但你需要:

  1. 克隆tensorflow开放模型zoo
  2. 根据上述说明these instructions. Alternatively, you can use this patch修补models/research/object_detection/exporter.py
  3. 按照 found here in your cloned repo. It's important to both follow the protobuf compilation steps AND update your python path for the slim libraries.
  4. 中的对象检测安装说明进行操作
  5. 按照 exporting a trained model for inference 的说明进行操作。请注意,重要说明的重要部分是下载的模型将出现三个 model.ckpt 文件名。需要传入导出脚本的文件名是这三个文件名的基础文件名。所以如果三个文件是/path/to/model.ckpt.data-00000-of-00001/path/to/model.ckpt.meta/path/to/model.ckpt.index,那么传递给脚本的参数是:/path/to/model.ckpt
  6. 享受你的新模型吧!