0

I am struggling to feed data to the tf.esitimator.DNNClassifier after reloading it through tf.contrib.predictor.from_saved_model. I would very much appreciate your help.

I found this and this links but I am getting an error. Below is my implementation:

Saving Model:

feature_spec = tf.feature_column.make_parse_example_spec(feat_cols)
export_fn = tf.estimator.export.build_parsing_serving_input_receiver_fn(feature_spec)
tuned_model.export_savedmodel('./model_dir/saved_models/', export_fn)

This successfully saves the model with the following info:

INFO:tensorflow:Calling model_fn. INFO:tensorflow:Done calling model_fn. INFO:tensorflow:Signatures INCLUDED in export for Classify: ['serving_default', 'classification'] INFO:tensorflow:Signatures INCLUDED in export for Regress: ['regression'] INFO:tensorflow:Signatures INCLUDED in export for Predict: ['predict'] INFO:tensorflow:Signatures INCLUDED in export for Train: None INFO:tensorflow:Signatures INCLUDED in export for Eval: None INFO:tensorflow:Restoring parameters from /nimble/kdalal/model_dir/model.ckpt-28917 INFO:tensorflow:Assets added to graph. INFO:tensorflow:No assets to write. INFO:tensorflow:SavedModel written to: ./model_dir/saved_models/temp-b'1556819228'/saved_model.pb

Reloading For Predictions:

predict_prod = tf.contrib.predictor.from_saved_model('./model_dir/saved_models/1556819228')
predict_prod(dict(X_test))

I get the following error:

ValueError: Got unexpected keys in input_dict: {'DOW', 'JOB_FUNCTION', 'ACC_SIZE', 'answered_20D', 'MatchType', 'CONTACT_STATE', 'SEASONS', 'called_20D', 'st_cb_ans_20D', 'JOB_ROLE', 'st_cb_called_20D', 'CALL_BLOCKS'} expected: {'inputs'}

My X_test is a data frame that I'm trying to get predictions for.

[EDITED]:

My input dict looks like as follows:

{'JOB_ROLE': 714859     Manager-Level
 714860     Manager-Level
 714861     Manager-Level
 714862     Manager-Level
 714863    Director-Level
 Name: JOB_ROLE, dtype: object,
 'JOB_FUNCTION': 714859    Information Technology
 714860    Information Technology
 714861    Information Technology
 714862    Information Technology
 714863    Information Technology
 Name: JOB_FUNCTION, dtype: object,
 'MatchType': 714859            Work Phone
 714860            Work Phone
 714861            Work Phone
 714862            Work Phone
 714863    Account Main Phone
 Name: MatchType, dtype: object,
 'CALL_BLOCKS': 714859    17_18
 714860    17_18
 714861    17_18
 714862    17_18
 714863    17_18
 Name: CALL_BLOCKS, dtype: object,
 'ACC_SIZE': 714859    StartUps
 714860    StartUps
 714861       Small
 714862    StartUps
 714863       Small
 Name: ACC_SIZE, dtype: object,
 'CONTACT_STATE': 714859    WA
 714860    CA
 714861    CA
 714862    CA
 714863    CA
 Name: CONTACT_STATE, dtype: object,
 'SEASONS': 714859    Spring
 714860    Spring
 714861    Spring
 714862    Spring
 714863    Spring
 Name: SEASONS, dtype: object,
 'DOW': 714859    Monday
 714860    Monday
 714861    Monday
 714862    Monday
 714863    Monday
 Name: DOW, dtype: object,
 'called_20D': 714859    0.038760
 714860    0.077519
 714861    0.217054
 714862    0.046512
 714863    0.038760
 Name: called_20D, dtype: float64,
 'answered_20D': 714859    0.000000
 714860    0.086957
 714861    0.043478
 714862    0.000000
 714863    0.130435
 Name: answered_20D, dtype: float64,
 'st_cb_called_20D': 714859    0.050233
 714860    0.282496
 714861    0.282496
 714862    0.282496
 714863    0.282496
 Name: st_cb_called_20D, dtype: float64,
 'st_cb_ans_20D': 714859    0.059761
 714860    0.314741
 714861    0.314741
 714862    0.314741
 714863    0.314741
 Name: st_cb_ans_20D, dtype: float64}

I am a beginner with tf and I don't know how to pass data frames to the model so that I can call predcit method and get the predictions.

Also, should I be converting my input data to some other dtype?

Krishnang K Dalal
  • 2,322
  • 9
  • 34
  • 55
  • [Can you post what your input dict looks like?](https://github.com/tensorflow/tensorflow/issues/13477) – Edeki Okoh May 02 '19 at 18:38
  • @EdekiOkoh - I have edited my question. Also, when I changed the inputs to `prod_predictions = predict_prod({'inputs':X_test.values})` it threw ***ValueError: Cannot feed value of shape (75116, 12) for Tensor 'input_example_tensor:0', which has shape '(?,)'*** error. – Krishnang K Dalal May 02 '19 at 18:45

2 Answers2

0

I found the answer. Please refer the link to understand how to feed data to the imported estimator model.

Krishnang K Dalal
  • 2,322
  • 9
  • 34
  • 55
0

ValueError: Cannot feed value of shape (75116, 12) for Tensor 'input_example_tensor:0', which has shape '(?,)

about this question your model looks like to predict once 1 item

you can only feed one item like {'inputs': X_test.values[0]}

you can change the model to predict bunch of item

Good luck

joyzaza
  • 186
  • 1
  • 8