python - 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 需要字符串类型?
解决方案
推荐阅读
- react-native - 初始化后开玩笑更改模拟
- spring - 打印语句被执行两次,这在 Spring 启动中的 run 方法调用之前存在
- javascript - 在打字稿中通过引用传递变量[Angular 8]
- amazon-web-services - 创建 AWS 粘合作业是否需要爬网程序?
- firebase - 带有列表的 Flutter Futurebuilder 不起作用
- r - Pettitt - R 中的显着性水平
- odoo - Odoo 13:为 odoo 13 api 启用 cors origin
- c++ - 在 C++ 对象中初始化数据成员的正确顺序
- powershell - 如何在PowerShell中保持大输出?
- html - 创建登录页面时出现代码错误