我使用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()
这就是我的拉力板的样子:
我应该如何设置input_tensor_shapes
和output_tensor_names
,这样我就不会收到错误,说我的TensorFlow图不包含具有该名称的张量。
发布于 2020-02-02 16:33:09
我建议使用Netron来查看TensorFlow文件。这使得图表更容易理解。
https://stackoverflow.com/questions/60027444
复制相似问题