jaried
jaried

Reputation: 672

Is my understanding of tensorflow v1 session correct?

I have the following code:

self.sess = tf.Session()
_, self.cost = self.sess.run(
    [self._train_op, self.loss],
    feed_dict={self.s: batch_memory[:, :self.n_features],
    self.q_target: q_target}
)

The order of execution as I understand it is:

self.cost=self.sess.run(
    [self.loss],feed_dict={self.s: batch_memory[:, :self.n_features], self.q_target: q_target})
_=self.sess.run([self._train_op],feed_dict={self.loss:self.cost})

Is my understanding correct?

Upvotes: 1

Views: 32

Answers (1)

user11530462
user11530462

Reputation:

The order of execution is sequential. Graph will be created in the same order the operations are defined inside the session.

Simple example:

import tensorflow as tf
x = 4
y = 5
add_op = tf.add(x, y, name='Add')
mul_op = tf.multiply(x, y, name='Multiply')
pow_op = tf.pow(add_op, mul_op, name='Power')
useless_op = tf.multiply(x, add_op, name='Useless')

with tf.Session() as sess:
    pow_out, useless_out = sess.run([pow_op, useless_op]) 

When fetch pow_op operation, it will first run the add_op and mul_op to get their output tensor and then run pow_op on them to compute the required output value. In other words useless_op will not be executed as it's output tensor is not used in executing the pow_op operation.

Upvotes: 1

Related Questions