1

It seems redundant to me to define twice the input function for the model and exporter. Why don't just use a unique input function in both the definition and the exporter

For example, for the MNIST images example where the input is an image of 28x28x1, the input_fn and serving_input_fn are as follow.

train_input_fn = tf.estimator.inputs.numpy_input_fn(
    x={INPUT_FEATURE: train_data},
    y=train_labels,
    batch_size=100,
    num_epochs=None,
    shuffle=True)

.

def serving_input_receiver_fn():
  inputs = {
    INPUT_FEATURE: tf.placeholder(tf.float32, [None, 28, 28, 1]),
  }
  return tf.estimator.export.ServingInputReceiver(inputs, inputs)

.

classifier.train(input_fn=train_input_fn, steps=FLAGS.steps)
classifier.export_savedmodel(DIR_MODEL,
        serving_input_receiver_fn=serving_input_receiver_fn)

At the end both define a dict {INPUT_FEATURE: image}

zeellos
  • 139
  • 11

1 Answers1

1

serving_input_fn is necessary when you want to make prediction which is used to define the input dtype with tf.placeholder. input_fn will return a dataset of source and target sequences for training which is used to train.

The answer be helpful.

twostarxx
  • 81
  • 1
  • 4