The tf.estimator
API takes input "input functions" that return Dataset
s. For example, Estimator.train()
takes an input_fn
(documentation).
In the examples I've seen, whenever this function is supplied manually, it is an argumentless lambda.
Doesn't that mean that the function always returns the same value? Or is it invoked multiple times with no arguments? I wasn't able to find documentation about this. Why don't functions like train()
just take input as a Dataset
explicitly?
Dataset
objects are also backed by nodes in the computational graph. The Estimator
constructs the computational graph on each all to train()
, evaluate()
etc. By doing so the Estimator
API ensures that operations on different Estimator
objects are isolated and Tensor
/Dataset
into independent graphs.
Some code pointers (for TensorFlow 1.7) in case you're interested:
Estimator.train()
eventually invokes this
input_fn
Hope that helps.
According to Tensorflow documentation:
"Estimators expect an input_fn to take no arguments. To work around this restriction, we use lambda to capture the arguments and provide the expected interface."
https://www.tensorflow.org/guide/datasets_for_estimators
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With