我创建了我的估算器:
estimator = tf.estimator.DNNClassifier(
hidden_units=[500, 100],
feature_columns=[embedded_text_feature_column],
n_classes=2,
optimizer=tf.train.AdagradOptimizer(learning_rate=0.003))
并将培训视为:
estimator.train(input_fn=train_input_fn, steps = 2)
完成这两个步骤后,我想保存我的模型/估算器。我尝试了以下方法:
# NOT SURE IF THE FOLLOWING FUNCTION IS CORRECT
def serving_input_receiver_fn():
"""Build the serving inputs."""
# The outer dimension (None) allows us to batch up inputs for
# efficiency. However, it also means that if we want a prediction
# for a single instance, we'll need to wrap it in an outer list.
inputs = {"x": tf.placeholder(shape=[None, 4], dtype=tf.float32)}
return tf.estimator.export.ServingInputReceiver(inputs, inputs)
export_dir = classifier.export_savedmodel(
export_dir_base="/home/suhail/tensorflow-stubs/",
serving_input_receiver_fn=serving_input_receiver_fn)
但这会引发错误说:Feature sentence if not in features dictionary
。我训练了模型as given in doc at text_classification_with_tf_hub
我做错了什么?