I'm trying to implement a basic RL model as a custom estimator and I'm facing some issue regarding the control flow and graph handling of estimators.
I have to run 2 passes on the graph, one for the current state and one for the next state.
Using the core api, I would execute a pass with the next state as input, and use the result to calculate the loss of the current state and update the graph but as estimator handle the session and graph I can't find a way to execute these steps in a model_fn.
I had a look at the tf.train.SessionRunHook interface but it doesn't seem to fit my need.
Is there a away to customize estimator execution flow to support this king of scenario?
(I cannot use any additional library like Keras)
--
You received this message because you are subscribed to the Google Groups "Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss+unsubscribe@tensorflow.org.
To post to this group, send email to dis...@tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/discuss/ac2c7053-f2c8-4b3d-ae32-84c16f05a6e0%40tensorflow.org.
# Define input functioninput_fn = tf.estimator.inputs.numpy_input_fn( x={"current_state": input_x, "next_state": input_x_}, y=input_y, shuffle=True)
# Define model functiondef model_fn(features, labels, mode, params): predictions = tf.layers.dense(features["current_state"], 1, activation=None, reuse=tf.AUTO_REUSE) predictions_ = tf.layers.dense(features["next_state"], 1, activation=None, reuse=tf.AUTO_REUSE) if mode == tf.estimator.ModeKeys.PREDICT: return tf.estimator.EstimatorSpec( mode=mode, predictions={"y_H": predictions}) loss = tf.losses.mean_squared_error(labels=predictions_, predictions=predictions) optimizer = tf.train.GradientDescentOptimizer( learning_rate=0.01) train_op = optimizer.minimize( loss=loss, global_step=tf.train.get_global_step()) return tf.estimator.EstimatorSpec( mode=mode, loss=loss, train_op=train_op)
regression = tf.estimator.Estimator(model_fn=model_fn)Estimators are not great for this kind of thing. If hooks don't work for you, you'd have to encode both passes in a single graph. That doesn't sound terrible to me, but it can get complicated.I see no good reason why you wouldn't be able to use tf.keras though (assuming that would solve your problem). It comes with TensorFlow and is part of the TemsorFlow API.
Martin
On Mar 16, 2018 2:54 AM, "alexis.gillain via Discuss" <dis...@tensorflow.org> wrote:
I'm trying to implement a basic RL model as a custom estimator and I'm facing some issue regarding the control flow and graph handling of estimators.
I have to run 2 passes on the graph, one for the current state and one for the next state.
Using the core api, I would execute a pass with the next state as input, and use the result to calculate the loss of the current state and update the graph but as estimator handle the session and graph I can't find a way to execute these steps in a model_fn.
I had a look at the tf.train.SessionRunHook interface but it doesn't seem to fit my need.
Is there a away to customize estimator execution flow to support this king of scenario?
(I cannot use any additional library like Keras)
--
You received this message because you are subscribed to the Google Groups "Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss+u...@tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/discuss/914eff3d-f000-4304-ac3b-d2e6269047e0%40tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/discuss/1ba4a8fd-079a-43f4-8cf4-199a8b0eb8ef%40tensorflow.org.