似乎我在TF 1.11中遇到了问题。
我正在使用Estimator API创建一个非常基本的估算器:
import tensorflow as tf
import numpy as np
train_input_fn = tf.estimator.inputs.numpy_input_fn(
x={"x": np.zeros([100], np.float64)},
y=np.ones([100], np.float64),
num_epochs=None,
shuffle=True)
train_spec = tf.estimator.TrainSpec(
input_fn=train_input_fn,
max_steps=2)
def serving_input_receiver_fn():
serialized_tf_example = tf.placeholder(dtype=tf.float64,
shape=[None, ],
name='input_tensors')
receiver_tensors = {'x': serialized_tf_example}
return tf.estimator.export.ServingInputReceiver(
receiver_tensors, receiver_tensors)
exporter = tf.estimator.LatestExporter(
name="latest",
serving_input_receiver_fn=serving_input_receiver_fn,
exports_to_keep=5)
eval_spec = tf.estimator.EvalSpec(
input_fn=train_input_fn,
steps=1,
throttle_secs=30,
start_delay_secs=0,
exporters=exporter)
feature_x = tf.feature_column.numeric_column("x", shape=[1])
feature_columns = [feature_x]
model = tf.estimator.DNNClassifier(feature_columns=feature_columns,
hidden_units=[2],
activation_fn=tf.nn.relu,
n_classes=2,
model_dir="./aa/")
training_results, export_dirs = tf.estimator.train_and_evaluate(
model,
train_spec,
eval_spec)
在这里,我只希望我的服务函数具有一个输入x的张量作为输入,我会手动将其提供给服务函数。 但是,当我运行train_and_evaluate时:
INFO:tensorflow:'serving_default' : Classification input must be a single string Tensor; got {'x': <tf.Tensor 'input_tensors:0' shape=(?,) dtype=float64>}
INFO:tensorflow:'classification' : Classification input must be a single string Tensor; got {'x': <tf.Tensor 'input_tensors:0' shape=(?,) dtype=float64>}
INFO:tensorflow:'regression' : Regression input must be a single string Tensor; got {'x': <tf.Tensor 'input_tensors:0' shape=(?,) dtype=float64>}
WARNING:tensorflow:Export includes no default signature!
有人知道为什么会这样吗? AFAIK我应该能够插入一个自定义的服务输入功能,尤其是在我的代码中没有使用“假定字符串张量”的情况,我认为这是通过TFRecords服务的。
谢谢!