首页 > 解决方案 > TypeError: 'ParseExample' Op 的输入'serialized' 的 float32 类型与预期的字符串类型不匹配

问题描述

我正在使用 Tensorflow 中的估计器开发一个用于图像分类的 CNN 神经网络。在保存过程中遇到此错误。以下是我保存部分的代码:

        def serving_input_rec_fn():
            serialized_tf_example = tf.placeholder(dtype=tf.float32,
                                                   # shape=[-1, self.num_input[0], self.num_input[1], 1],
                                                   name='input')
            receiver_tensors = {"myInput": serialized_tf_example}
            feature_spec = {"examples": tf.FixedLenFeature(shape=[self.num_input[0], self.num_input[1]], dtype=tf.float32)}
            features = tf.parse_example(serialized_tf_example, feature_spec)
            return tf.estimator.export.ServingInputReceiver(features, receiver_tensors)

        model.export_savedmodel(export_dir, serving_input_rec_fn,
                                     strip_default_attrs=True)

错误似乎是在 tf.parse_example 函数的 serialized_tf_example 参数中,它期望数据类型为字符串。但我的输入图像类型实际上是 float32。我该如何解决这个问题?在我对占位符的理解中,当模型被导出以供服务时,它将作为主图的输入子图。因此,为什么 serialized_tf_example 需要字符串类型?

标签: pythontensorflowdeep-learning

解决方案


推荐阅读