How to pass variable to a tensorflow graph?

Edit


Lately, I am learning and playing with TensorFlow (entered a whole new fantasy world surrounded by python, jupyter notebook, numpy, pickle, scikit-learn). It was fine until I am trying to play around with some given codes in a online course, I am trying to assign different value to the "Beta" of seeing the effect of "regularization". It took me some time to figure out how to do this simple value assignments.

The backgrounds are like this:
- I have created a beta_arr  ( beta_arr = [0.1,0.01,0.001] ) with all the value I want to test for beta (outside the code tf.Session block)
- Within the tf.Session block, I want loop through the beta_arr and assign the beta where it is being used in a statement within the tf.Graph block

What I did:
- added a line "tf_beta = 0.1" before the tf.Graph block
- within tf.Graph, I changed all the variable name for "beta" into "tf_beta"
- before the tf.Session block, created a for loop to loop through beta_arr ("for beta in beta_arr:"), and within the loop I added "tf_beta = beta"

My solution above kind of answer the question in this stackoverflow post : https://stackoverflow.com/questions/41930725/tensorflow-pass-an-integer-to-graph

For the tensorflow expert out there, please let me know if I have done anything wrong as I am still a tf newbie :P








How to pass variable to a tensorflow graph? How to pass variable to a tensorflow graph? Reviewed by DF on 12:53:00 AM Rating: 5
©DF. Powered by Blogger.