【问题标题】:input_alternative error on export_savedmodel in TensorflowTensorflow 中 export_savedmodel 的 input_alternative 错误
【发布时间】:2017-08-11 11:35:49
【问题描述】:

我有一个简单的 LinearModel,它有两个稀疏特征和两个实值特征。我训练了它,现在我想用 export_savedmodel 导出它。参考一些资料,我想出了一些类似的东西:

feature_spec = create_feature_spec_for_parsing(
    [
        real_valued_column_1, real_valued_column_2,
        sparse_column_1, sparce_column_2
    ]
)
input_receiver_fn = tf.estimator.export.build_parsing_serving_input_receiver_fn(feature_spec)
my_estimator.export_savedmodel('my_model/', serving_input_fn=input_receiver_fn)

地点:

real_valued_column_1 = tf.contrib.layers.real_valued_column(
    'avg_consumption_h')
sparse_column_1 = tf.contrib.layers.sparse_column_with_integerized_feature("sparse_1", bucket_size=24)

不幸的是,我在export_savedmodel 上收到了ValueError: A default input_alternative must be provided.。我深入研究了 tensorflow 的代码库,似乎 build_parsing_serving_input_receiver_fn 总是返回 ServingInputReceiver 但如果传递给 export_savedmodel 的 serving_input_fn 不是 InputFnOps 类型,则提取 input_alternatives 的方法总是将它们创建为空。

build_parsing_serving_input_receiver_fn 是否以某种方式被弃用,在提取 input_alternative 的过程中出现问题,或者我完全误解了过程并做错了什么?

我使用 python 3.6 和 tensorflow 1.2,我的模型是一个简单的tf.contrib.learn.LinearRegressor

【问题讨论】:

标签: python machine-learning tensorflow


【解决方案1】:

你可以试试下面的

from tensorflow.contrib.learn.python.learn.utils.input_fn_utils import build_parsing_serving_input_fn
input_receiver_fn = build_parsing_serving_input_fn(feature_spec)

【讨论】:

  • 谢谢,它有效! The current docs 虽然仍然指向 cl0udburst 使用的版本,但您能否提供更多提示它的作用以及为什么不同?
猜你喜欢
  • 2018-01-20
  • 2017-05-13
  • 1970-01-01
  • 2017-08-30
  • 2018-05-04
  • 2016-03-12
  • 1970-01-01
  • 1970-01-01
  • 2016-02-16
相关资源
最近更新 更多