I trained a Tensorflow Estimator Model. When I tried to export the model to saved_model.pb file I wrote the following code to serve the input function which I have to predict.
def csv_serving_input():
feature_placeholders = {
'renancy': tf.placeholder(tf.float32, [None]),
'freq': tf.placeholder(tf.float32, [None]),
'monetary': tf.placeholder(tf.float32, [None])
}
features = feature_placeholders
return tf.estimator.export.ServingInputReceiver(features,
feature_placeholders)
and to export the model
model = "trained_model/cluster_01"
export_dir = model_dir + "/export"
estimator.export_savedmodel(export_dir, csv_serving_input)
It throws following error ValueError: too many values to unpack (expected 2)
I am posting full traceback error for the reference
<ipython-input-93-ecb2562febb3> in <module>()
----> 1 estimator.export_savedmodel(export_dir, csv_serving_input_fn_vtwo)
c:\users\madhivarman\appdata\local\programs\python\python35\lib\site-packages\tensorflow\contrib\learn\python\learn\estimators\estimator.py in export_savedmodel(self, export_dir_base, serving_input_fn, default_output_alternative_key, assets_extra, as_text, checkpoint_path, graph_rewrite_specs, strip_default_attrs)
1386 input_ops = serving_input_fn()
1387 input_alternatives, features = (
-> 1388 saved_model_export_utils.get_input_alternatives(input_ops))
1389
1390 # TODO(b/34388557) This is a stopgap, pending recording model provenance.
c:\users\madhivarman\appdata\local\programs\python\python35\lib\site-packages\tensorflow\python\util\deprecation.py in new_func(*args, **kwargs)
248 'in a future version' if date is None else ('after %s' % date),
249 instructions)
--> 250 return func(*args, **kwargs)
251 return tf_decorator.make_decorator(
252 func, new_func, 'deprecated',
c:\users\madhivarman\appdata\local\programs\python\python35\lib\site-packages\tensorflow\contrib\learn\python\learn\utils\saved_model_export_utils.py in get_input_alternatives(input_ops)
171 input_alternatives[DEFAULT_INPUT_ALTERNATIVE_KEY] = default_inputs
172 else:
--> 173 features, unused_labels = input_ops
174
175 if not features:
ValueError: too many values to unpack (expected 2)
I have attached Github Repo for full code reference
Can you try this:
def serving_input_fn():
feature_placeholders = {
'var1' : tf.placeholder(tf.float32, [None]),
'var2' : tf.placeholder(tf.float32, [None]),
...
}
features = {
key: tf.expand_dims(tensor, -1)
for key, tensor in feature_placeholders.items()
}
return tf.estimator.export.ServingInputReceiver(features,
feature_placeholders)