gpt4 book ai didi

python - 导出tensorflow模型时为"Cannot infer num from shape"

转载 作者:行者123 更新时间:2023-11-30 09:19:10 25 4
gpt4 key购买 nike

我正在尝试导出像这样的 tensorflow 模型

  feature_spec = { 'words': tf.FixedLenSequenceFeature([], tf.int64, allow_missing=True) }

def serving_input_receiver_fn():
"""Build the serving inputs."""
serialized_tf_example = tf.placeholder(dtype=tf.string,
shape=[1],
name='input_example_tensor')
features = tf.parse_example(serialized_tf_example, feature_spec)
receiver_tensors = {'words': serialized_tf_example}
return tf.estimator.export.ServingInputReceiver(features, receiver_tensors)

export_dir = classifier.export_savedmodel(export_dir_base=args.job_dir,
serving_input_receiver_fn=serving_input_receiver_fn)

但我收到此错误

Cannot infer num from shape (1, ?, 128, 128)

我不知道来自哪里,我猜它来自tf.parse_example。关于我在这里做错了什么有什么想法吗?

最佳答案

在不知道完整原因的情况下,这段代码似乎工作得很好

  def serving_input_receiver_fn():
feature_spec = { "words": tf.FixedLenFeature(dtype=tf.int64, shape=[4]) }
return tf.estimator.export.build_parsing_serving_input_receiver_fn(feature_spec)()

关于python - 导出tensorflow模型时为"Cannot infer num from shape",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46474151/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com