0
$\begingroup$

I have the following code that I have simplified:

class someClass():
 def __init__(self):
   self.u_pred, self.v_pred = self.fnc(self.x_tf, self.y_tf)
   self.sess = tf.compat.v1.Session(config=tf.compat.v1.ConfigProto(allow_soft_placement=True,
                                                     log_device_placement=True))
   def predict(self, x, y):
    
     tf_dict = {self.x_tf: x, self.y_tf: y}
    
     u = self.sess.run(self.u_pred, tf_dict)
     v = self.sess.run(self.v_pred, tf_dict)
     return u, v

Here how does sess.run able to fetch self.u_pred and self.v_pred when they are not even part of the graph as they havent been declared using tf.placeholder? After going through this question, my understanding is that session calls the tf.placeholder and fetches the first argument passed and evaluates with the dictionary provided.

So in this case does self.sess.run(self.u_pred, tf_dict) able to automatically find self.fnc() and plugs in tf_dict = {self.x_tf: x, self.y_tf: y} to auto-evaluate the function?

$\endgroup$

1 Answer 1

1
$\begingroup$

TF graphs are frozen when you first create the session. Most tensorflow function definitions within a graph experience this event. As soon as this event happens, you are enabled to add new or existing functions. After you do this process, the new or existing functions (you added) become frozen too. Note you may be using an outdated version of tf. This is significant as tf workflows may change after each major tf release, given that some tf functions may get deprecated.

$\endgroup$
8
  • $\begingroup$ can you please elaborate what does function definitions experience this event mean? $\endgroup$ Commented Jan 20 at 14:19
  • $\begingroup$ so does self.sess.run(self.u_pred, tf_dict) able to automatically find self.fnc()? $\endgroup$ Commented Jan 20 at 14:20
  • $\begingroup$ Also frozen in my understanding means that all the state of variables, hyperparameters being frozen as part of the graph's latest epoch (currently not trainalbe). But how does this it relates to my quetion of how TF graph is able to access output of a function that has not been declared as part of the graph before using placeholders $\endgroup$ Commented Jan 20 at 14:24
  • $\begingroup$ @user_04248753498 i wrote function definitions within a graph experience this event not function definitions experience this event. The graph portion is key. I am not sure epochs have anything to do here since you cannot dynamically add new functions during training/fitting to my knowledge. Other relevant information is in the source code link I included in my answer. If you think I answered your original question, please upvote or mark it as the answer. Other follow up questions are excellent candidates for future questions to the community. $\endgroup$
    – Full Array
    Commented Jan 20 at 14:34
  • 1
    $\begingroup$ @user_04248753498 frozen because tf definitions and operations are added to the graph. They are not executed eagerly. I suggest you go thru the source code and docs for the version of tf you are using. i checked your code again. You may be using an outdated tf that has deprecated functions that changes tf workflows comprared to recent tf versions. If you have an outdated PC, kaggle and similar services give you basic but free options to run notebooks with the latest tf. $\endgroup$
    – Full Array
    Commented Jan 21 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.