如何将对象检测模型(在其冻结图形中)转换为.tflite,而不需要任何输入和输出数组的知识

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

所以我有一个从“https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md”下载的物体检测模型;模型的名称是“faster_rcnn_resnet101_fgvc”。我尝试将模型转换为.tflite格式(因为我有冻结图“frozen_inference_graph.pb”),使用https://www.tensorflow.org/lite/guide/ops_select中给出的python代码:

import tensorflow as tf

graph_def_file = "/path/to/Downloads/mobilenet_v1_1.0_224/frozen_graph.pb"
input_arrays = ["input"]
output_arrays = ["MobilenetV1/Predictions/Softmax"]

converter = tf.lite.TFLiteConverter.from_frozen_graph(
  graph_def_file, input_arrays, output_arrays)
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)

运行这个给了我一个错误:

ValueError: Invalid tensors 'input' were found.

有没有办法找到模型的输入和输出节点?我只有冻结图,GraphDef和检查点。

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

要查找可以使用的模型的输入和输出节点,saved_model_cli

!saved_model_cli show --all --dir faster_rcnn_resnet101_fgvc_2018_07_19/saved_model/

它将显示有关您的模型的详细信息。

MetaGraphDef with tag-set: 'serve' contains the following SignatureDefs:

signature_def['serving_default']:
  The given SavedModel SignatureDef contains the following input(s):
    inputs['inputs'] tensor_info:
        dtype: DT_UINT8
        shape: (-1, -1, -1, 3)
        name: image_tensor:0
  The given SavedModel SignatureDef contains the following output(s):
    outputs['detection_boxes'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1, 5, 4)
        name: detection_boxes:0
    outputs['detection_classes'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1, 5)
        name: detection_classes:0
    outputs['detection_scores'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1, 5)
        name: detection_scores:0
    outputs['num_detections'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1)
        name: num_detections:0
  Method name is: tensorflow/serving/predict

在您的情况下,输入图层名称是"image_tensor"

© www.soinside.com 2019 - 2024. All rights reserved.