Tensorflow version 1.10
Using: DNNClassifier
and tf.estimator.FinalExporter
I'm using the Iris example from TF blog. I defined the following code:
# The CSV features in our training & test data.
COLUMN_NAMES = ['SepalLength',
'SepalWidth',
'PetalLength',
'PetalWidth',
'Species']
FEATURE_COLUMNS = COLUMN_NAMES[:4]
INPUT_COLUMNS = [
tf.feature_column.numeric_column(column) for column in COLUMN_NAMES
]
def serving_input_receiver_fn():
"""Build the serving inputs."""
inputs = {}
for feat in INPUT_COLUMNS:
inputs[feat.name] = tf.placeholder(shape=[None], dtype=feat.dtype)
return tf.estimator.export.ServingInputReceiver(inputs, inputs)
This is how I call my functions:
train_spec = tf.estimator.TrainSpec(
train_input, max_steps=hparams.train_steps)
exporter = tf.estimator.FinalExporter(
'iris', serving_input_receiver_fn)
eval_spec = tf.estimator.EvalSpec(
eval_input,
steps=hparams.eval_steps,
exporters=[exporter],
name='iris-eval')
run_config = tf.estimator.RunConfig(
session_config=_get_session_config_from_env_var())
run_config = run_config.replace(model_dir=hparams.job_dir)
print('Model dir: %s', run_config.model_dir)
estimator = model.build_estimator(
# Construct layers sizes.
config=run_config,
hidden_units=[10, 20, 10],
n_classes=3)
tf.estimator.train_and_evaluate(estimator, train_spec, eval_spec)
I get the following messages:
INFO:tensorflow:Done calling model_fn.
INFO:tensorflow:Signatures INCLUDED in export for Eval: None
INFO:tensorflow:Signatures INCLUDED in export for Classify: None
INFO:tensorflow:Signatures INCLUDED in export for Regress: None
INFO:tensorflow:Signatures INCLUDED in export for Predict: ['predict']
INFO:tensorflow:Signatures INCLUDED in export for Train: None
INFO:tensorflow:Signatures EXCLUDED from export because they cannot be be served via TensorFlow Serving APIs:
INFO:tensorflow:'serving_default' : Classification input must be a single string Tensor; got {'SepalLength': <tf.Tensor 'Placeholder:0' shape=(?,) dtype=float32>, 'PetalLength': <tf.Tensor 'Placeholder_2:0' shape=(?,) dtype=float32>, 'PetalWidth': <tf.Tensor 'Placeholder_3:0' shape=(?,) dtype=float32>, 'SepalWidth': <tf.Tensor 'Placeholder_1:0' shape=(?,) dtype=float32>, 'Species': <tf.Tensor 'Placeholder_4:0' shape=(?,) dtype=float32>}
INFO:tensorflow:'classification' : Classification input must be a single string Tensor; got {'SepalLength': <tf.Tensor 'Placeholder:0' shape=(?,) dtype=float32>, 'PetalLength': <tf.Tensor 'Placeholder_2:0' shape=(?,) dtype=float32>, 'PetalWidth': <tf.Tensor 'Placeholder_3:0' shape=(?,) dtype=float32>, 'SepalWidth': <tf.Tensor 'Placeholder_1:0' shape=(?,) dtype=float32>, 'Species': <tf.Tensor 'Placeholder_4:0' shape=(?,) dtype=float32>}
WARNING:tensorflow:Export includes no default signature!
When I print serving_input_receiver_fn
I get:
ServingInputReceiver(features={'sepal_width': <tf.Tensor 'Placeholder_1:0' shape=(?, 1) dtype=float32>, 'petal_width': <tf.Tensor 'Placeholder_3:0' shape=(?, 1) dtype=float32>, 'sepal_length': <tf.Tensor 'Placeholder:0' shape=(?, 1) dtype=float32>, 'petal_length': <tf.Tensor 'Placeholder_2:0' shape=(?, 1) dtype=float32>}, receiver_tensors={'sepal_width': <tf.Tensor 'Placeholder_1:0' shape=(?, 1) dtype=float32>, 'petal_width': <tf.Tensor 'Placeholder_3:0' shape=(?, 1) dtype=float32>, 'sepal_length': <tf.Tensor 'Placeholder:0' shape=(?, 1) dtype=float32>, 'petal_length': <tf.Tensor 'Placeholder_2:0' shape=(?, 1) dtype=float32>}, receiver_tensors_alternatives=None)
In the export folder there is nothing (CSV, JSON, etc.):
gs://<my-bucket>/iris/iris_20181014_214916/export/:
gs://<my-bucket>/iris/iris_20181014_214916/export/
I found a solution here.