简体   繁体   English

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

[英]How to convert an object detection model, in it's frozen graph, to a .tflite, without any knowledge of input and output arrays

So I have an object detection model downloaded from " https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md "; 所以我有一个从“ https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md ”下载的对象检测模型; the name of the model is "faster_rcnn_resnet101_fgvc". 模型的名称是“faster_rcnn_resnet101_fgvc”。 I tried to convert the model to a .tflite format (since I had the frozen graph "frozen_inference_graph.pb"), using a python code given in https://www.tensorflow.org/lite/guide/ops_select : 我试图将模型转换为.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)

Running this gave me an error: 运行这个给了我一个错误:

ValueError: Invalid tensors 'input' were found.

Is there a way I can find the input and output nodes of the model? 有没有办法找到模型的输入和输出节点? I only have the frozen graph, GraphDef, and checkpoints. 我只有冻结图,GraphDef和检查点。

To find out input and output nodes of the model you can use, saved_model_cli 要查找可以使用的模型的输入和输出节点saved_model_cli

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

It will show detaild information about your 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

In your case input layer name is "image_tensor" 在您的情况下,输入图层名称是"image_tensor"

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

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