mlmodel 的输出形状为空。为什么形状是空的?
mlmodel's output shape is empty. Why is shape empty?
我学习了本教程 https://www.tensorflow.org/tutorials/generative/cyclegan 并且完成的模型在 windows 上运行良好。然后我将此 tf 模型转换为 mlmodel,但模型的输出(MultiArray)具有空形状。我该如何解决这个问题...? (此模型的EPOCH为1)
计算机::: windows10 / tensorflow 和 -gpu 2.2 / tfcoreml 1.1
这是转换代码
import tfcoreml
import coremltools
from tensorflow import keras
saved_model = keras.models.load_model('saved_model')
# get input, output node names for the TF graph from the Keras model
input_name = (saved_model.inputs[0].name.split(':')[0])[0:7]
keras_output_node_name = saved_model.outputs[0].name.split(':')[0]
graph_output_node_name = keras_output_node_name.split('/')[-1]
# Saving the Core ML model to a file.
model = tfcoreml.convert('saved_model',
image_input_names=input_name,
input_name_shape_dict={input_name: [1, 540, 540, 3]},
output_feature_names=[graph_output_node_name],
minimum_ios_deployment_target='13',
red_bias=-123.68,
green_bias=-116.78,
blue_bias=-103.94)
model.save('./saved_mlmodel/saved_model.mlmodel')
这是saved_model.summary
Model: "model_1"
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_2 (InputLayer) [(None, None, None, 0
__________________________________________________________________________________________________
sequential_15 (Sequential) (None, None, None, 6 3072 input_2[0][0]
__________________________________________________________________________________________________
sequential_16 (Sequential) (None, None, None, 1 131328 sequential_15[0][0]
__________________________________________________________________________________________________
sequential_17 (Sequential) (None, None, None, 2 524800 sequential_16[0][0]
__________________________________________________________________________________________________
sequential_18 (Sequential) (None, None, None, 5 2098176 sequential_17[0][0]
__________________________________________________________________________________________________
sequential_19 (Sequential) (None, None, None, 5 4195328 sequential_18[0][0]
__________________________________________________________________________________________________
sequential_20 (Sequential) (None, None, None, 5 4195328 sequential_19[0][0]
__________________________________________________________________________________________________
sequential_21 (Sequential) (None, None, None, 5 4195328 sequential_20[0][0]
__________________________________________________________________________________________________
sequential_22 (Sequential) (None, None, None, 5 4195328 sequential_21[0][0]
__________________________________________________________________________________________________
sequential_23 (Sequential) (None, None, None, 5 4195328 sequential_22[0][0]
__________________________________________________________________________________________________
concatenate_1 (Concatenate) multiple 0 sequential_23[0][0]
sequential_21[0][0]
sequential_24[0][0]
sequential_20[0][0]
sequential_25[0][0]
sequential_19[0][0]
sequential_26[0][0]
sequential_18[0][0]
sequential_27[0][0]
sequential_17[0][0]
sequential_28[0][0]
sequential_16[0][0]
sequential_29[0][0]
sequential_15[0][0]
__________________________________________________________________________________________________
sequential_24 (Sequential) (None, None, None, 5 8389632 concatenate_1[0][0]
__________________________________________________________________________________________________
sequential_25 (Sequential) (None, None, None, 5 8389632 concatenate_1[1][0]
__________________________________________________________________________________________________
sequential_26 (Sequential) (None, None, None, 5 8389632 concatenate_1[2][0]
__________________________________________________________________________________________________
sequential_27 (Sequential) (None, None, None, 2 4194816 concatenate_1[3][0]
__________________________________________________________________________________________________
sequential_28 (Sequential) (None, None, None, 1 1048832 concatenate_1[4][0]
__________________________________________________________________________________________________
sequential_29 (Sequential) (None, None, None, 6 262272 concatenate_1[5][0]
__________________________________________________________________________________________________
conv2d_transpose_15 (Conv2DTran (None, None, None, 3 6147 concatenate_1[6][0]
==================================================================================================
Total params: 54,414,979
Trainable params: 54,414,979
Non-trainable params: 0
这是mlmodel.spec描述
input {
name: "input_2"
type {
imageType {
width: 540
height: 540
colorSpace: RGB
}
}
}
output {
name: "Identity"
type {
multiArrayType {
dataType: FLOAT32
}
}
}
metadata {
userDefined {
key: "coremltoolsVersion"
value: "3.4"
}
}
这通常不是问题。当你 运行 模型时,你仍然会得到一个正确形状的多数组。
如果您已经知道该形状,则可以将其填入,以便它显示在 mlmodel 文件中,但这更多的是为了文档目的。
我学习了本教程 https://www.tensorflow.org/tutorials/generative/cyclegan 并且完成的模型在 windows 上运行良好。然后我将此 tf 模型转换为 mlmodel,但模型的输出(MultiArray)具有空形状。我该如何解决这个问题...? (此模型的EPOCH为1)
计算机::: windows10 / tensorflow 和 -gpu 2.2 / tfcoreml 1.1
这是转换代码
import tfcoreml
import coremltools
from tensorflow import keras
saved_model = keras.models.load_model('saved_model')
# get input, output node names for the TF graph from the Keras model
input_name = (saved_model.inputs[0].name.split(':')[0])[0:7]
keras_output_node_name = saved_model.outputs[0].name.split(':')[0]
graph_output_node_name = keras_output_node_name.split('/')[-1]
# Saving the Core ML model to a file.
model = tfcoreml.convert('saved_model',
image_input_names=input_name,
input_name_shape_dict={input_name: [1, 540, 540, 3]},
output_feature_names=[graph_output_node_name],
minimum_ios_deployment_target='13',
red_bias=-123.68,
green_bias=-116.78,
blue_bias=-103.94)
model.save('./saved_mlmodel/saved_model.mlmodel')
这是saved_model.summary
Model: "model_1"
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_2 (InputLayer) [(None, None, None, 0
__________________________________________________________________________________________________
sequential_15 (Sequential) (None, None, None, 6 3072 input_2[0][0]
__________________________________________________________________________________________________
sequential_16 (Sequential) (None, None, None, 1 131328 sequential_15[0][0]
__________________________________________________________________________________________________
sequential_17 (Sequential) (None, None, None, 2 524800 sequential_16[0][0]
__________________________________________________________________________________________________
sequential_18 (Sequential) (None, None, None, 5 2098176 sequential_17[0][0]
__________________________________________________________________________________________________
sequential_19 (Sequential) (None, None, None, 5 4195328 sequential_18[0][0]
__________________________________________________________________________________________________
sequential_20 (Sequential) (None, None, None, 5 4195328 sequential_19[0][0]
__________________________________________________________________________________________________
sequential_21 (Sequential) (None, None, None, 5 4195328 sequential_20[0][0]
__________________________________________________________________________________________________
sequential_22 (Sequential) (None, None, None, 5 4195328 sequential_21[0][0]
__________________________________________________________________________________________________
sequential_23 (Sequential) (None, None, None, 5 4195328 sequential_22[0][0]
__________________________________________________________________________________________________
concatenate_1 (Concatenate) multiple 0 sequential_23[0][0]
sequential_21[0][0]
sequential_24[0][0]
sequential_20[0][0]
sequential_25[0][0]
sequential_19[0][0]
sequential_26[0][0]
sequential_18[0][0]
sequential_27[0][0]
sequential_17[0][0]
sequential_28[0][0]
sequential_16[0][0]
sequential_29[0][0]
sequential_15[0][0]
__________________________________________________________________________________________________
sequential_24 (Sequential) (None, None, None, 5 8389632 concatenate_1[0][0]
__________________________________________________________________________________________________
sequential_25 (Sequential) (None, None, None, 5 8389632 concatenate_1[1][0]
__________________________________________________________________________________________________
sequential_26 (Sequential) (None, None, None, 5 8389632 concatenate_1[2][0]
__________________________________________________________________________________________________
sequential_27 (Sequential) (None, None, None, 2 4194816 concatenate_1[3][0]
__________________________________________________________________________________________________
sequential_28 (Sequential) (None, None, None, 1 1048832 concatenate_1[4][0]
__________________________________________________________________________________________________
sequential_29 (Sequential) (None, None, None, 6 262272 concatenate_1[5][0]
__________________________________________________________________________________________________
conv2d_transpose_15 (Conv2DTran (None, None, None, 3 6147 concatenate_1[6][0]
==================================================================================================
Total params: 54,414,979
Trainable params: 54,414,979
Non-trainable params: 0
这是mlmodel.spec描述
input {
name: "input_2"
type {
imageType {
width: 540
height: 540
colorSpace: RGB
}
}
}
output {
name: "Identity"
type {
multiArrayType {
dataType: FLOAT32
}
}
}
metadata {
userDefined {
key: "coremltoolsVersion"
value: "3.4"
}
}
这通常不是问题。当你 运行 模型时,你仍然会得到一个正确形状的多数组。
如果您已经知道该形状,则可以将其填入,以便它显示在 mlmodel 文件中,但这更多的是为了文档目的。