如何导出tflite模型制作器model_spec以供离线使用?

问题描述 投票:0回答:1

我正在使用 tflite 模型制作者 effectivedet_lite3 模型进行对象检测。 基本设置如下:

import numpy as np
import os
from tflite_model_maker.config import ExportFormat, QuantizationConfig
from tflite_model_maker import model_spec
from tflite_model_maker import object_detector
from tflite_support import metadata
import tensorflow as tf

assert tf.__version__.startswith('2')
tf.get_logger().setLevel('ERROR')
from absl import logging
logging.set_verbosity(logging.ERROR)


train_data = object_detector.DataLoader.from_pascal_voc(
    'my_data/train',
    'my_data/train',
    ['obj']
)

val_data = object_detector.DataLoader.from_pascal_voc(
    'my_data/validate',
    'my_data/validate',
    ['obj']
)

spec = model_spec.get('efficientdet_lite3')

model = object_detector.create(train_data, model_spec=spec, batch_size=4, train_whole_model=True, epochs=200, validation_data=val_data)

它在可以访问互联网的机器上运行良好,甚至可以产生一些可用的结果。 但是在没有互联网接入的机器上,我收到了 urlopen 错误,我认为这是由于从互联网获取模型规范而引起的。

现在可以在这里找到并下载该模型本身: https://www.kaggle.com/models/tensorflow/efficientdet/frameworks/tensorFlow2/variations/lite3-detection 但我不知道如何创建自定义 model_spec 对象进行训练。

您能帮我设置这个项目以实现完全离线使用吗? 这对我来说很重要,因为训练数据位于连接到封闭网络的离线计算机上,每次将此数据传输到其他计算机是一个痛苦的过程。将必要的 tflite 数据传输到离线机器会容易得多。

我尝试过使用这个规范: https://www.tensorflow.org/lite/api_docs/python/tflite_model_maker/object_detector/EfficientDetLite3Spec 并将其指向本地 saving_model.pb 文件,但我收到各种奇怪的错误,例如:

ERROR:absl:hub.KerasLayer is trainable but has zero trainable weights.

    ValueError: Could not find matching concrete function to call loaded from the SavedModel. Got:
      Positional arguments (1 total):
        * <tf.Tensor 'imgs:0' shape=(None, 512, 512, 3) dtype=float32>
      Keyword arguments: {}
    
     Expected these arguments to match one of the following 1 option(s):

python tensorflow tensorflow-lite tflite
1个回答
0
投票

仍然遇到同样的问题...我解决的唯一方法是在线训练并在边缘设备中离线加载保存的模型。

您也可以尝试仅使用tensorflow 2.0,然后将其导出为tflite格式。使用此方法,您可以离线加载 effectivedet 模型的权重

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.