如何获得从Darknet转换的.pb模型的输入和输出名称

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

我使用YOLOv3-SPP模型在暗网上训练了一个模型。我需要能够在我的iPhone应用程序中使用此模型,因此需要将其转换为CoreML。我首先将.weights文件转换为.pb文件。现在,我尝试使用tfcoreml将其从TensorFlow转换为CoreML。但是我似乎无法确定我的输入和输出张量名称。我试图使用tensorboard来可视化模型并确定输入和输出,但是由于我对TensorFlow还是很陌生,所以我不知道该使用什么。我正在使用此脚本将模型从TensorFlow转换为CoreML:

import tfcoreml
import os
import tensorflow as tf

frozen_model_file = os.path.abspath('frozen_darknet_yolov3_model.pb')
input_tensor_shapes = {"input/placeholder:0": [1, 32, 32, 9]}
# Output CoreML model path
coreml_model_file = './model.mlmodel'
output_tensor_names = ['output/prediction:0']
def convert():
    # Read the pb model
    with tf.gfile.GFile(frozen_model_file, "rb") as f:
        graph_def = tf.GraphDef()
        graph_def.ParseFromString(f.read())
    # Then, we import the graph_def into a new Graph
    tf.import_graph_def(graph_def, name="")
    # Convert
    tfcoreml.convert(
        tf_model_path=frozen_model_file,
        mlmodel_path=coreml_model_file,
        input_name_shape_dict=input_tensor_shapes,
        output_feature_names=output_tensor_names)
convert()

这是我的张量板外观:

enter image description here

我也应该设置input_tensor_shapesoutput_tensor_names,以便不会出现错误,表明我的TensorFlow图不包含具有该名称的张量。

python tensorflow tensorboard coreml coremltools
1个回答
1
投票

我建议使用Netron查看TensorFlow文件。它使图形更易于理解。

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