How to get a link by variable / placeholder name?

By name, I mean:

tf.placeholder(tf.float32, name='NAME') tf.get_variable("W", [n_in, n_out],initializer=w_init()) 

I have several placeholders that I want to access from external functions without passing a link, provided that there are those that store these names, how can you get a link to them? (this is all at the time of plotting, not at runtime)

And my second question: how can I get all the variables that contain the given name, regardless of scope?

Example: all my weights have the name "W" in many areas, I want all of them to be included in the list. I do not want to add them manually. The same thing can be done with prejudices, say, I want to make a histogram.

+8
source share
1 answer

First of all, you can get the placeholder using tf.Graph.get_tensor_by_name () . For example, if you are working with the default schedule:

 placeholder1 = tf.placeholder(tf.float32, name='NAME') placeholder2 = tf.get_default_graph().get_tensor_by_name('NAME:0') assert placeholder1 == placeholder2 

Secondly, I would use the following function to get all the variables with the given name (regardless of their size):

 def get_all_variables_with_name(var_name): name = var_name + ':0' return [var for var in tf.all_variables() if var.name.endswith(name)] 
+12
source

All Articles