0

我学习了本教程https://www.tensorflow.org/tutorials/generation/cyclegan并且完成的模型在 Windows 上运行良好。然后我将此 tf 模型转换为 mlmodel,但模型的输出(MultyArray)具有空形状。我该如何解决这个问题...?(此型号的 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"
  }
}
4

1 回答 1

0

这通常不是问题。当你运行模型时,你仍然会得到一个正确形状的多数组。

如果您已经知道该形状,则可以将其填充以使其显示在 mlmodel 文件中,但这更多是出于文档目的而不是其他任何目的。

于 2020-06-12T09:28:15.647 回答