1

I am trying to follow this tutorial of the Tensorflow: https://www.tensorflow.org/versions/master/tutorials/input_fn/index.html#building-the-input-fn

Defining the regressor:

regressor = tf.contrib.learn.DNNRegressor(
        feature_columns=feature_cols, 
        hidden_units=[10,10]
)

Training it:

regressor.fit(input_fn=lambda: input_fn(training_set), steps=5500)

My problems come from the next step. They are about the result of the prediction.

Prediction:

The standard version that tutorial provided:

y = regressor.predict(input_fn=lambda: input_fn(prediction_set))
print ("Predictions: {}".format(str(y)))

But the output is not what I expect, it gives me:

Predictions: <generator object _infer_model_as_iterable at 0x7f8134159aa0>

And I also tried to inspect its type:

print type(y)

#return: <type 'generator'>

Can anyone explain the question?

Cuo Show
  • 235
  • 1
  • 3
  • 11
  • There was the exact same question yesterday, you can see the answer here: http://stackoverflow.com/a/40706423/1951176 – sygi Nov 21 '16 at 09:30
  • @sygi Thanks for your answer! I just tried this method, however, it stuck at the conversion stage `list(y)`. Python keeps running for conversion( only 7 entities in the prediction set). – Cuo Show Nov 21 '16 at 11:45
  • @sygi It keeps occupying about 20% computation resource of GPU and it doesn't appear to stop. – Cuo Show Nov 21 '16 at 12:12
  • What happens if you do only `print(y.next())`? Anyway, it's a problem with the model, not the generator itself. – sygi Nov 21 '16 at 12:35
  • @sygi The `.next()` works fine. I guess I need to use a loop to get values. Does generator know how many entities in it? I guess I may need to set the number of iteration manually. – Cuo Show Nov 22 '16 at 01:51

0 Answers0